July 30, 2010



----- 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 1:01:57 AM
> Subject: Re: [phobos] Calling abort() on unhandled exception
> 
> Sean Kelly wrote:
> > On Jul 29, 2010, at 9:37 PM, Andrei Alexandrescu  wrote:
> > 
> >> Sean Kelly wrote:
> >>> On Jul 29, 2010,  at 8:21 PM, Walter Bright wrote:
> >>>> Andrei Alexandrescu  wrote:
> >>>>> 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.
> >>>>> 
> >>>> It's  reasonable for seg fault exceptions to produce a core dump. It isn't
>for  recoverable Exceptions, or for non-recoverable ones like out of  memory.
> >>> At the moment, we don't differentiate between seg faults  and
>non-recoverable errors.  Though seg faults are only thrown as  exceptions on Windows which doesn't have core dumps anyway, as far as I know.  For what it's worth, I was investigating this bug:
> >>>   http://d.puremagic.com/issues/show_bug.cgi?id=4385
> >> I see. Overall,  my opinion is that regular exceptions that escape main(0
>should simply print  their error message to stderr and exit(1). There should be no stack trace,  abort(), core dump, or anything worse than that. Print the string and exit(1).  Anything more will force most people to actually insert a try/catch in  main
> >>  to do the simple thing.
> > 
> > I think the  stack trace at least should remain. People have been begging for
>that for years,  and I do think it's pretty useful. Simply
> > printing an error message says  nothing about the context, and it's context that gives error messages  meaning.
> 
> I for one really enjoy stuff like:
> 
> void main(string[]  args)
> {
>     enforce(args.length > 1, "Usage: prog  arg");
>     ...
> }

void usageEnforce(bool condition)
{
  if(!condition)
  {
     writeln("Usage: prog arg");
     exit(1);
  }
}

Please, let's leave stack traces for exceptions that escape main.  It's not a condition that most developers plan on happening.  When the unexpected exception happens, you can be lost without a stack trace.  All you get is something like this:

Uncaught exception in someModuleYouDidntWrite(123): parameter should be > 0

I do hope to see better stack traces than what we currently get though...

-Steve




July 30, 2010
Le 2010-07-30 ? 1:01, Andrei Alexandrescu a ?crit :

> Exception messages are meant to be seen by users.

I disagree.

The error message of an exception might be meaningful in a small program that does only one thing at a time, but in general to give the user an understandable error message you need more context information.

For instance, say you have a command line program that takes as input a HTTP URL and downloads a web page with all its related content. Outputting an error such as "Socket could not connect to host 1.2.3.4 on port 80: timeout" is quite cryptic because you don't even know which sub-resource it was trying to fetch, nor why it fetched that resource (it might be that the HTML parser didn't get the domain name correctly). And anyway it's probably a bug because it should just have skipped that resource and went on. If you want to debug that you need a stack trace to know which resource handler should have caught that exception, and you might want to attach the debugger to stop when the uncaught exception is thrown and inspect the circumstances.

And you probably don't want to handle localization inside the exception handling mechanism either.

Also, for GUI programs an uncaught exception is always a bug because it'll make the application suddenly quit with no message visible to the user. Exiting a GUI application with abort() on OSX will ensure that the OS shows an error message about the application having crashed, and for GUI applications OSX will save a quite helpful crash report the user can then send to the developer. You don't want uncaught exceptions to silently quit the application and just be logged to the system console with no stack trace.

So I believe in the vast majority of cases calling abort() and showing a stack trace is what you want. That's what most other languages do. It's easy to get what Andrei wants with a "try {...} catch (Exception e) { writeln(e); exit(-1); }" in the main, but I'd generally recommend against this.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



July 30, 2010

Steve Schveighoffer, el 30 de julio a las 03:44 me escribiste:
> Wouldn't this be useless?  That is, do you care about a core dump when the stack is unwound (and the source of the problem is gone from the stack)?
> 
> If this is all you want, why not write your main that way?
> 
> BTW, my opinion is that an uncaught exception should not dump core.  It should print a stack trace and exit with non-zero exit code.  I understand the reasoning behind it, but dumping core is not a normal mode of operation for most users.  They don't know what to do with a core file, and silently dumping core on a system where one is not expecting it can fill up a filesystem.

Come on! Read the whole mail. abort() != dumping a core.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Es mucho mas probable que el salchich?n sea primavera a que la primavera
sea salchich?n.
	-- Peperino P?moro

July 30, 2010

Andrei Alexandrescu, el 29 de julio a las 21:37 me escribiste:
> Sean Kelly wrote:
> >On Jul 29, 2010, at 8:21 PM, Walter Bright wrote:
> >>Andrei Alexandrescu wrote:
> >>>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.
> >>>
> >>It's reasonable for seg fault exceptions to produce a core dump. It isn't for recoverable Exceptions, or for non-recoverable ones like out of memory.
> >
> >At the moment, we don't differentiate between seg faults and non-recoverable errors.  Though seg faults are only thrown as exceptions on Windows which doesn't have core dumps anyway, as far as I know. For what it's worth, I was investigating this bug:
> >
> >http://d.puremagic.com/issues/show_bug.cgi?id=4385
> 
> I see. Overall, my opinion is that regular exceptions that escape
> main(0 should simply print their error message to stderr and
> exit(1). There should be no stack trace, abort(), core dump, or
> anything worse than that. Print the string and exit(1). Anything
> more will force most people to actually insert a try/catch in main
> to do the simple thing.

Calling abort() on Linux will simply print "Aborted". Do you think is that bad that worth being completely different than any other PL and making debug an uncaught exception almost imposible???

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Hey you, don't tell me there's no hope at all
Together we stand, divided we fall.

July 30, 2010

Andrei Alexandrescu, el 29 de julio a las 22:01 me escribiste:
> Sean Kelly wrote:
> >On Jul 29, 2010, at 9:37 PM, Andrei Alexandrescu wrote:
> >
> >>Sean Kelly wrote:
> >>>On Jul 29, 2010, at 8:21 PM, Walter Bright wrote:
> >>>>Andrei Alexandrescu wrote:
> >>>>>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.
> >>>>>
> >>>>It's reasonable for seg fault exceptions to produce a core dump. It isn't for recoverable Exceptions, or for non-recoverable ones like out of memory.
> >>>At the moment, we don't differentiate between seg faults and non-recoverable errors.  Though seg faults are only thrown as exceptions on Windows which doesn't have core dumps anyway, as far as I know. For what it's worth, I was investigating this bug:
> >>> http://d.puremagic.com/issues/show_bug.cgi?id=4385
> >>I see. Overall, my opinion is that regular exceptions that
> >>escape main(0 should simply print their error message to stderr
> >>and exit(1). There should be no stack trace, abort(), core dump,
> >>or anything worse than that. Print the string and exit(1).
> >>Anything more will force most people to actually insert a
> >>try/catch in main
> >> to do the simple thing.
> >
> >I think the stack trace at least should remain. People have been
> >begging for that for years, and I do think it's pretty useful.
> >Simply
> >printing an error message says nothing about the context, and it's
> >context that gives error messages meaning.
> 
> I for one really enjoy stuff like:
> 
> void main(string[] args)
> {
>     enforce(args.length > 1, "Usage: prog arg");
>     ...
> }
> 
> Having a stack trace tacked there... not good. Exception messages are meant to be seen by users. Stack traces are meant to be seen by the programmer. The fact that we print both by default doesn't sit well at all.

That's not an exception!!!! What's the point of that???? Why don't you
just write a library function like like enforce but that uses exit(1)
instead of throwing an exception for that?!?!?! You really want to
sacrifice the correct behavior for this dumb, dumb "feature"???
This really makes me mad! God...

Plus *ANY* other programming language mark uncaught exceptions as
OBVIOUS ERRORS (they print traces or abort()).

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
El d?a que falten los ni?os, que sobren las mujeres y que se prenda
fuego el ?ltimo ?rbol, ser? el Apocal?psis.
	-- Ricardo Vaporeso. Camino Negro, 1916.

July 30, 2010
On Jul 29, 2010, at 10:01 PM, Andrei Alexandrescu wrote:
> 
> I for one really enjoy stuff like:
> 
> void main(string[] args)
> {
>    enforce(args.length > 1, "Usage: prog arg");
>    ...
> }
> 
> Having a stack trace tacked there... not good. Exception messages are meant to be seen by users. Stack traces are meant to be seen by the programmer. The fact that we print both by default doesn't sit well at all.

Fair enough.  Maybe they should only be displayed for Errors, not Exceptions?

> Is it reasonable to say that Exception is the "nicer" thing and Throwable is the "less nice" thing that is handled differently? Then come bus errors, which are "not nice at all".

It is.
July 30, 2010
That's the thing.  With Leandro's proposed behavior, the stack isn't unwound because the exception is effectively never caught.  The runtime can still print the error message like it does now, it just works as if from a signal handler.

On Jul 30, 2010, at 3:44 AM, Steve Schveighoffer wrote:

> Wouldn't this be useless?  That is, do you care about a core dump when the stack is unwound (and the source of the problem is gone from the stack)?
> 
> If this is all you want, why not write your main that way?
> 
> BTW, my opinion is that an uncaught exception should not dump core.  It should print a stack trace and exit with non-zero exit code.  I understand the reasoning behind it, but dumping core is not a normal mode of operation for most users.  They don't know what to do with a core file, and silently dumping core on a system where one is not expecting it can fill up a filesystem.
> 
> -Steve
> 
> 
> 
> ----- Original Message ----
>> From: Leandro Lucarella <luca at llucax.com.ar>
>> To: Discuss the phobos library for D
>> <public-phobos-4o3eaN+cb9R8UrSeD/g0lQ at plane.gmane.org>
>> Sent: Thu, July 29, 2010 11:20:55 PM
>> Subject: Re: [phobos] Calling abort() on unhandled exception
>> 
>> 
>> 
>> 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
>> 
>> _______________________________________________
>> phobos mailing  list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos

July 30, 2010
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.

-Steve



----- Original Message ----
> From: Sean Kelly <sean at invisibleduck.org>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Fri, July 30, 2010 10:42:51 AM
> Subject: Re: [phobos] Calling abort() on unhandled exception
> 
> On Jul 29, 2010, at 10:01 PM, Andrei Alexandrescu wrote:
> > 
> > I for  one really enjoy stuff like:
> > 
> > void main(string[] args)
> >  {
> >    enforce(args.length > 1, "Usage: prog  arg");
> >    ...
> > }
> > 
> > Having a stack trace  tacked there... not good. Exception messages are meant
>to be seen by users.  Stack traces are meant to be seen by the programmer. The fact that we print both  by default doesn't sit well at all.
> 
> Fair enough.  Maybe they should  only be displayed for Errors, not Exceptions?
> 
> > Is it reasonable to  say that Exception is the "nicer" thing and Throwable is
>the "less nice" thing  that is handled differently? Then come bus errors, which are "not nice at  all".
> 
> It is.
> _______________________________________________
> phobos  mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
> 



July 30, 2010



----- Original Message ----
> From: Sean Kelly <sean at invisibleduck.org>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Fri, July 30, 2010 10:46:38 AM
> Subject: Re: [phobos] Calling abort() on unhandled exception
> 
> That's the thing.  With Leandro's proposed behavior, the stack isn't  unwound
>because the exception is effectively never caught.  The runtime can  still print the error message like it does now, it just works as if from a  signal handler.
>

With stack trace?  I'd much rather have a stack trace than a core file.  A stack trace can easily be read, is easy to email/attach to a bug report, and does not require duplicating the entire environment to use.

-Steve




July 30, 2010
Another alternative is deriving all exceptions that shouldn't show a trace by default from an exception with a custom toString that omits this info.

Sent from my iPhone

On Jul 30, 2010, at 7:50 AM, Steve Schveighoffer <schveiguy at yahoo.com> 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.
> 
> -Steve
> 
> 
> 
> ----- Original Message ----
>> From: Sean Kelly <sean at invisibleduck.org>
>> To: Discuss the phobos library for D <phobos at puremagic.com>
>> Sent: Fri, July 30, 2010 10:42:51 AM
>> Subject: Re: [phobos] Calling abort() on unhandled exception
>> 
>> On Jul 29, 2010, at 10:01 PM, Andrei Alexandrescu wrote:
>>> 
>>> I for  one really enjoy stuff like:
>>> 
>>> void main(string[] args)
>>> {
>>>   enforce(args.length > 1, "Usage: prog  arg");
>>>   ...
>>> }
>>> 
>>> Having a stack trace  tacked there... not good. Exception messages are meant
>> to be seen by users.  Stack traces are meant to be seen by the programmer. The fact that we print both  by default doesn't sit well at all.
>> 
>> Fair enough.  Maybe they should  only be displayed for Errors, not Exceptions?
>> 
>>> Is it reasonable to  say that Exception is the "nicer" thing and Throwable is
>> the "less nice" thing  that is handled differently? Then come bus errors, which are "not nice at  all".
>> 
>> It is.
>> _______________________________________________
>> phobos  mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>> 
> 
> 
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos