ctrl+c and destructors

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 3 18:57:37 PDT 2013


On Friday, October 04, 2013 02:55:36 Andrej Mitrovic wrote:
> On 10/4/13, Walter Bright <newshound2 at digitalmars.com> wrote:
> > Continuing program execution after it failed due to programming bugs is
> > just a bad, bad, bad idea, and it needs to die.
> 
> Then why did you introduce the Error exception type into the language
> in the first place? I mean why would you let exceptions propagate up
> the call stack if the state of the program is seriously compromised?
> Why not just call the system's exit() function?
> 
> If nobody up the call stack could do anything useful, then there's no
> point in walking up the call stack. And yet we have Error that does
> exactly that.
> 
> What I'm saying is the act of throwing an Error itself is an act of
> continuing program execution after a serious failure. And here you are
> arguing against it.

I've actually been wondering about that too. The only case I can think of 
where catching an Error and continuing _might_ make sense would be with 
OutOfMemoryError if you caught it right after it was thrown and then did 
something differently based on the fact that you'd run out of memory. But 
pretty much all other Errors are outright programming bugs, and all you really 
need is the stacktrace. Unwinding the stack (even with skipping destructors, 
finally blocks, etc.) seems extraneous at that point.

- Jonathan M Davis


More information about the Digitalmars-d mailing list