Re: My lesson for today



rush wrote:

> My mental image was that
> ensure just gets executed moment you get out of the block either normaly,
> or by exception, and in that image if ensure was nested inside exception
> handler, it would surely be executed before exception handler.

I don't know if this will help any, but your picture wasn't far wrong. Not
wrong at all in fact, except for one thing -- when the exception handler is
invoked, you haven't /yet/ left the block. If you set a handler, then the
handler code will be executed as if it had been invoked at the point where the
signal was thown.

That's different from the way that (say) C++ and Java work, where the system
first unwinds the stack back to where the handler was set and only then invokes
the handler.

The good thing about that is that you can have resumable exceptions (very
useful in some circumstances). The downside is that setting an exception
handler can't be made entirely free[*] (some code always has to execute even if
the exception is never thrown) unlike Java where using a try/catch block has
zero runtime overhead unless the exception is actually thrown.

-- chris

([*] unless the implementation is pretty sophisticated)


.



Relevant Pages

  • Re: CLI Exception Handling
    ... the exception, but not on the same instruction that actually generated the ... functionality does exist in win32 SEH. ... handler executes all finally blocks that were lower on the stack have ... >> really can do is make a decision to continue searching or execute the ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Try Finally...
    ... Now we can protect every more or less specialized action ... an error indication (exception or error code) has to be ... an according exception handler can be inserted into the code. ... resources, as they are related to specific actions. ...
    (comp.lang.pascal.delphi.misc)
  • Re: CLI Exception Handling
    ... It is practically quite difficult to determine (in the handler block) from which IL instruction the exception was thrown. ... >> really can do is make a decision to continue searching or execute the ...
    (microsoft.public.dotnet.framework.clr)
  • Re: WinForms bug? ThreadException not invoked on Exceptions in system code pre-processing the me
    ... Message Queue and invoking the appropriate handler. ... if an Exception is raised during the PRE-PROCESSING of a Windows ... And because any handling will probably fail if there is no memory, the CLR will terminate the application without attempting to call the ApplicationException or UnhandledException events. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: BackgroungWork taske ended for no appearent reason
    ... To do the same thing with Try/Catch blocks requires wrapping every file access with a Do While ... ... If there was any exception thrown in your DoWork event handler, ... If the operation raises an exception that your code does not handle, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)