Error derived from Exception is WRONG, DAMNIT

Sean Kelly sean at invisibleduck.org
Sat Mar 1 18:45:34 PST 2008


== Quote from Yigal Chripun (yigal100 at gmail.com)'s article
> My point is that errors have the same relation to exceptions. There is
> additional functionality that  exceptions provide ( you can catch them
> and do stuff) which are not part of an error's interface. Errors should
> represent unrecoverable situations where the program must terminate.
> catching an error is, as downs said, a BUG.

So the problem then becomes which errors to classify as non-recoverable.  Particularly in a systems
language like D, I would be hesitant to dictate that almost any errors must necessarily terminate the
program.  Consider an array bounds error.  This is a system-generated error that clearly indicates a
program flaw, and yet the program is still in a valid state.  The same could be said of other errors as
well.  When considering adding an Error class to Tango, I ended up deciding that there were very few if
any errors that I felt were non-recoverable in every program where they may occur.  Ultimately, it seems
to make more sense to leave the decision to the programmer to determine recoverability.  If the
programmer really wants to generate an error intended to be unrecoverable, he can always throw an
Object anyway.  Sure, Objects can still be caught, but I think few programs actually do this (outside the
catch{} statement anyway).


Sean



More information about the Digitalmars-d mailing list