Re: My lesson for today
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Sep 2005 16:47:08 +0100
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)
.
- References:
- My lesson for today
- From: rush
- Re: My lesson for today
- From: Bill Schwab
- Re: My lesson for today
- From: rush
- My lesson for today
- Prev by Date: Re: My lesson for today
- Next by Date: Abstract Presenters
- Previous by thread: Re: My lesson for today
- Next by thread: Abstract Presenters
- Index(es):
Relevant Pages
|