[phobos] Calling abort() on unhandled exception

Leandro Lucarella luca at llucax.com.ar
Thu Jul 29 20:20:55 PDT 2010



Andrei Alexandrescu, el 29 de julio a las 19:51 me escribiste:
> Walter Bright wrote:
> >I think we misunderstand each other. A file copy program that
> >fails due to, say, the disk being full, should not produce a core
> >dump. It should produce an error message like:
> >
> >  error: disk full
> >
> >An uncaught exception is NOT an invalid or crashed program in D.
> 
> I think Sean talks about Throwable objects that are not Exception objects.

I think (and hope) he talks about bug 4385.

Please, please, please, pretty please, call abort() at least on
Linux, is what every Linux programmer expects, I find debugging an
accidentally uncaught exception in D almost impossible.

Is not that bad for lazy people either, just add 4 lines to you main:

try {
// program
} catch (Exception e) {
        writeln(e);
}

Or whatever. Add a library function or an optional exception handler for
people wanting to shadow exceptions and make it look like a normal
termination.

BTW, *most Linux distributions don't dump cores by default* (you have to
change the ulimit to enable that feature, but if you run the program
inside a debugger, you'll get the exact backtrace where the exception
was originally thrown), so this doesn't mean that programs will be
dumping cores all over the places. I think part of the confusion about
implying that calling abort() will dump a core is because the title of
the bug report is incorrect, what I meant was uncaught exceptions should
call abort() (and I'm changing it right now). The runtime will probably
print just "Aborted" by that is triggered by SIGABRT, not abort(). So in
a common Linux distribution, a D program that exited because an uncaught
exception will just print (no core generated):
error: disk full
Aborted
Which seems reasonable.

Please also note that almost *ALL* programming languages treats uncaught
exception as errors and not normal program termination, most even print
a stack trace to show is a programming error.

[1] http://d.puremagic.com/issues/show_bug.cgi?id=4385

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
EXPOSICION INTERNACIONAL DE INODOROS
	-- Crónica TV



More information about the phobos mailing list