[phobos] Calling abort() on unhandled exception

Walter Bright walter at digitalmars.com
Thu Jul 29 17:07:04 PDT 2010


Unhandled exceptions should print the error message associated with the 
exception. This is so that, for example, you can write a file copy 
program without paying any attention to error messages. If an error 
happens, the program will print the right error message.

Getting a core dump instead would be most unattractive.

Sean Kelly wrote:
> (posted here because so few people read the druntime list)
>
> I've been working on allowing core dumps to be created when an unhandled exception is thrown in a D app.  To avoid some weirdness that arises when an exception is thrown beyond the scope of (C) main() I'm calling abort() after terminating everything possible and reporting the exception.  What I'm wondering is whether this is an acceptable way to terminate a D app in this situation or if I should do something else.  I was looking at the Win32 docs for abort() and they're a bit weird:
>
>     By default, the abort routine prints the message:
>
>     "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."
>
>     It then calls raise(SIGABRT).
>
> Even on OSX I see an "Abort trap" message in the console when I exit an app in this way.  I'm inclined to think that this isn't acceptable and that I should just try and sort out the weirdness that results from throwing an object outside of main(), but I thought I'd ask here for suggestions.  As an alternative I could call asm HLT, but this may bypass too much C-level runtime stuff.  Thoughts?
>
>   


More information about the phobos mailing list