From: Dave Cantrell Date: 2006-02-15T15:05:17+09:00 Subject: Re: Rescuing blocks? Hal Fulton wrote: > Dave Cantrell wrote: >> Eric Hodel wrote: >> >>> >>> You're going to get a performance hit setting up an exception trap >>> this way. >> >> Time for some down-South edumucation. What kind of performance hit are >> we talking about here? And why the hit at all? >> >> (I seem to recall reading somewhere once upon a time about memory >> stack stuff, but I'm not an old-school C-programmer so I never had to >> deal with it --- unfortunately for me...) > > Well, my knowledge is limited. Someone else can answer better. > > But look at it from a common-sense standpoint. Exceptions aren't > magic. Everything Ruby does can be done in assembly language, it's > just more verbose. > > I would think that exceptions, at the lowest level, work something > like: > > if something_happened_here > goto the_place_where_exceptions_are_caught > > So at the very least, catching exceptions means that you're doing > some sort of comparison or conditional branch. And this is code > that doesn't have to be run/generated *unless* you are catching > exceptions. > > Just my naive take. > > > Hal > > > That's kind of along the lines of what I was thinking, just better said. But this makes me wonder: (a) Worrying about the performance hit from comparison/conditional branching leads to the question "is all branching in blocks bad?" Obviously not. (b) Couldn't you say that *any* conditional could be jumping out to another section of code? i.e. not just exception handlers? if this_is_true goto where_we_do_stuff_when_this_is_true Hmm. This is something I've read, and it's in my brain somewhere, but I don't know it well enough to grok it yet. Especially at midnight... :( But your explanation gives me a better idea of what is happening, even with my questions. Thanks! -dave