try...catch slooowness?
Walter Bright
newshound2 at digitalmars.com
Mon Dec 20 16:53:23 PST 2010
Michel Fortin wrote:
> Exceptions are slow, that's a fact of life. The idea is that an
> exception should be exceptional, so the case to optimize for is the case
> where you don't have any exception: a try...catch that doesn't throw.
> Other ways to implement exceptions exists which are faster at throwing
> (setjmp for instance), but they're also slower at entering and exiting a
> try..catch block when no exception occur.
[...]
> Exceptions are recommended to avoid cluttering your normal code flow
> with error handling code. Clearly, in the code above exceptions are part
> of the normal code flow. That's not what exception are made for.
Right on all counts. Exceptions are for *exceptional* cases, i.e. unexpected
errors, not normal control flow.
The implementation is designed so that the speed normal execution is strongly
favored over speed of exception handling.
More information about the Digitalmars-d
mailing list