[phobos] Calling abort() on unhandled exception

Steve Schveighoffer schveiguy at yahoo.com
Fri Jul 30 09:36:05 PDT 2010


What's hard about using something other than exceptions to print usage in short 
scripts?

This looks just as readable/easy to me:

import std.usage;

int main(string[] args)
{
   checkUsage(args.length > 1, "Usage: prog args");
   ....
}

I also would like to see stack traces in small scripts too, esp. when the script 
isn't throwing the exception.

-Steve



----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Fri, July 30, 2010 11:52:33 AM
> Subject: Re: [phobos] Calling abort() on unhandled exception
> 
> Steve Schveighoffer wrote:
> > Um, no.  Exceptions can easily be  uncaught (oops, forgot a try catch!).  I 
>don't want the end result of an  uncaught exception to be a bug that's 
>impossible or difficult to determine  because no stack trace was printed.  Let's 
>consider that an exception may  not be easily repeated and is most likely 
>encountered by a user, not a  developer.  Giving a mechanism to communicate the 
>problem as completely as  possible from the user developer should be the 
>default.
> > 
> > We  should classify any exception or error that gets thrown outside of main 
>to be an  exception that was not planned for by the developer, and therefore a 
>program  error.  This should trigger as much info as possible, definitely 
>including  a stack trace, and possibly a core dump (though, dumping core after 
>catching an  exception is next to useless).
> > 
> > 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.
> 
> It  comes back to doing a sensible thing by default. main() without a try/catch 
>is  common in short scripts. I am currently _exceedingly_ happy that I'm able to  
>write 10-line scripts that do something interesting and behave reasonably in all  
>circumstances. Obviously, a stack trace is not something anyone would be  
>interested in for a short script. You are saying that I should take a size hit  
>in order to protect you from adding 6 lines to a 100,000 lines program.
> 
> D  should be script-friendly, it's a huge boon and a huge appeal, and stack 
>traces  don't go with script friendliness. Serious programs can afford the 
>slight  overhead.
> 
> See my  point?
> 
> 
> Andrei
> _______________________________________________
> phobos  mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
> 


      


More information about the phobos mailing list