DIP33: A standard exception hierarchy
John Colvin
john.loughran.colvin at gmail.com
Mon Apr 1 09:00:38 PDT 2013
On Monday, 1 April 2013 at 12:12:56 UTC, Lars T. Kyllingstad
wrote:
> But if all cleanup code is bypassed, what is the point in using
> the exception mechanism in the first place? Why not just
> abort() and be done with it?
>
> I can think of two reasons for throwing an Error rather than
> aborting directly:
> 1. You want a kind of "graceful" shutdown, in which destructors
> *are* called and make their best attempt at cleaning things up.
> 2. You want to catch it at some point, and perform some manual
> cleanup.
>
> But if (1) does not happen, can you even hope to do something
> useful with (2)? Your program is in the worst possible state
> it can be!
I'm no expert on these things, but:
Any chance of being in an invalid state - > undefined behaviour
Undefined behaviour - > your destructors/cleanup routine could in
theory do anything.
Therefore, you're better off not trying to cleanup if program
state could be invalid.
Anything that doesn't signal a possible invalid state should be
sensibly catchable and run destructors etc. , anything that does
should cut through the program like a knife and is catchable at
your own risk.
More information about the Digitalmars-d
mailing list