[phobos] Calling abort() on unhandled exception

Andrei Alexandrescu andrei at erdani.com
Fri Jul 30 16:14:19 PDT 2010


Michel Fortin wrote:
> Le 2010-07-30 à 11:52, Andrei Alexandrescu a écrit :
> 
>> Steve Schveighoffer wrote:
>>> If you want to avoid printing stack traces, catch the exception
>>> inside of main.  I don't think it's too much to ask.
>> That argument goes both ways, i.e. I could tell you it's not much
>> to ask to insert a try/catch if you care about the stack trace.
> 
> Calling abort() before unwinding the stack also has the advantage
> that if you have a debugger hooked it'll stop you right there and
> you'll have the full state of the program available at the moment the
> exception was thrown *before* unwinding the stack.
> 
> 
>> D should be script-friendly, it's a huge boon and a huge appeal,
> 
> That's true.
> 
>> and stack traces don't go with script friendliness.
> 
> I disagree. Stack traces can be useful when debugging a script.
> Imagine your 10-line script uses a library that has a bug in it, and
> all you get is the message from an exception thrown by a function
> from another library used by that first library. Without a stack
> trace you're totally lost.

Look at all scripts you've ever written or read. Scripts are not 
conceived to figure out a bug in a library. They are conceived to get 
something done quickly. If a script fails, you change it and try it 
again. Nobody writes a script expecting to debug a library with it.

Let me say that I just gave a talk at Google and presented a few short 
scripts that actually did something useful. People really warmed up to 
that. I think it's very important for D to stay script-friendly.

> If you want to throw error messages to the user using the exception
> mechanism, then there could be a special exception class for that.
> But normal exceptions aren't things that should be seen by the user;
> and if the user sees them he'll probably seek your help and the first
> thing you'll want is to know in what context the exception was
> thrown: a stack trace and if necessary a debugger stopped right where
> it happened.

Scripts don't obey these needs. Is it really too much to ask that if 
you're writing a serious application you want to place a guard at main() 
level? I mean the marginal cost is virtually nil. Why hurt casual script 
users to save a few lines of a large application?


Andrei


More information about the phobos mailing list