| Thread overview | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
The runtime can do one of two things: print exceptions according to a standard format and inject the msg field in the proper place or it can call toString. Which should be done? I prefer the former because it makes for a standard presentation and doesn't risk allocating memory needlessly, but I can see how people might do fancy stuff in toString that they expect to be used instead. This came up because I'm adding a default stack trace handler, and the current behavior prints the stack trace twice, so something needs to change. | ||||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | At what point do you need to print exceptions in runtime? Is that if an exception leaves main()?
Andrei
On 04/07/2010 10:29 AM, Sean Kelly wrote:
> The runtime can do one of two things: print exceptions according to a standard format and inject the msg field in the proper place or it can call toString. Which should be done? I prefer the former because it makes for a standard presentation and doesn't risk allocating memory needlessly, but I can see how people might do fancy stuff in toString that they expect to be used instead. This came up because I'm adding a default stack trace handler, and the current behavior prints the stack trace twice, so something needs to change.
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
| |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | On 07/04/10 16:29, Sean Kelly wrote:
> The runtime can do one of two things: print exceptions according to a standard format and inject the msg field in the proper place or it can call toString. Which should be done? I prefer the former because it makes for a standard presentation and doesn't risk allocating memory needlessly, but I can see how people might do fancy stuff in toString that they expect to be used instead. This came up because I'm adding a default stack trace handler, and the current behavior prints the stack trace twice, so something needs to change.
I think the better option would be to print them in the standard format, at least by default. You could always include several trace handlers to allow the user to effortlessly pick the handler they want, rather than everyone implementing their own for when they want to use toString.
| |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Related question: should toString add the stack trace or not?
On Apr 7, 2010, at 8:39 AM, Andrei Alexandrescu wrote:
> At what point do you need to print exceptions in runtime? Is that if an exception leaves main()?
>
> Andrei
>
> On 04/07/2010 10:29 AM, Sean Kelly wrote:
>> The runtime can do one of two things: print exceptions according to a standard format and inject the msg field in the proper place or it can call toString. Which should be done? I prefer the former because it makes for a standard presentation and doesn't risk allocating memory needlessly, but I can see how people might do fancy stuff in toString that they expect to be used instead. This came up because I'm adding a default stack trace handler, and the current behavior prints the stack trace twice, so something needs to change.
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
| |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | IMHO the reasonable default if a program crashes due to a completely unexpected exception is for the stack trace to be printed. Therefore, yes, toString should add the stack trace. On Wed, Apr 7, 2010 at 12:36 PM, Sean Kelly <sean at invisibleduck.org> wrote: > Related question: should toString add the stack trace or not? > > On Apr 7, 2010, at 8:39 AM, Andrei Alexandrescu wrote: > > > At what point do you need to print exceptions in runtime? Is that if an > exception leaves main()? > > > > Andrei > > > > On 04/07/2010 10:29 AM, Sean Kelly wrote: > >> The runtime can do one of two things: print exceptions according to a > standard format and inject the msg field in the proper place or it can call toString. Which should be done? I prefer the former because it makes for a standard presentation and doesn't risk allocating memory needlessly, but I can see how people might do fancy stuff in toString that they expect to be used instead. This came up because I'm adding a default stack trace handler, and the current behavior prints the stack trace twice, so something needs to change. > >> _______________________________________________ > >> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100407/761633fb/attachment-0001.html> | |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to David Simcha | The display when an exception escapes main() will include the stack trace no matter what. I'm mostly wondering what toString is intended for with exceptions.
On Apr 7, 2010, at 9:37 AM, David Simcha wrote:
> IMHO the reasonable default if a program crashes due to a completely unexpected exception is for the stack trace to be printed. Therefore, yes, toString should add the stack trace.
>
> On Wed, Apr 7, 2010 at 12:36 PM, Sean Kelly <sean at invisibleduck.org> wrote: Related question: should toString add the stack trace or not?
>
> On Apr 7, 2010, at 8:39 AM, Andrei Alexandrescu wrote:
>
> > At what point do you need to print exceptions in runtime? Is that if an exception leaves main()?
> >
> > Andrei
> >
> > On 04/07/2010 10:29 AM, Sean Kelly wrote:
> >> The runtime can do one of two things: print exceptions according to a standard format and inject the msg field in the proper place or it can call toString. Which should be done? I prefer the former because it makes for a standard presentation and doesn't risk allocating memory needlessly, but I can see how people might do fancy stuff in toString that they expect to be used instead. This came up because I'm adding a default stack trace handler, and the current behavior prints the stack trace twice, so something needs to change.
> >> _______________________________________________
> >> 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
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
| |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | On Wed, Apr 07, 2010 at 09:40:11AM -0700, Sean Kelly wrote: > I'm mostly wondering what toString is intended for with exceptions. For what its worth, what I generally use it for is dumping exceptions to a file for me to review later, without killing the program: void main() { while(true) try whatever; catch(Exception e) log.append(e.toString()); } So, I'd like toString to give all the info it has, including the stack trace. -- Adam D. Ruppe http://arsdnet.net | |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Apr 7, 2010, at 9:53 AM, Adam D. Ruppe wrote:
> On Wed, Apr 07, 2010 at 09:40:11AM -0700, Sean Kelly wrote:
>> I'm mostly wondering what toString is intended for with exceptions.
>
> For what its worth, what I generally use it for is dumping exceptions to a file for me to review later, without killing the program:
>
> void main() {
> while(true)
> try
> whatever;
> catch(Exception e)
> log.append(e.toString());
> }
>
> So, I'd like toString to give all the info it has, including the stack trace.
Hm... I guess the result of toString should be consistent with what's printed when an exception escapes main() then, and since a user can override toString, the default behavior should be to print toString and not bother with any custom display. I guess some memory allocations and such on exit aren't a big deal anyway.
| |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | On Wed, Apr 7, 2010 at 1:05 PM, Sean Kelly <sean at invisibleduck.org> wrote: > I guess some memory allocations and such on exit aren't a big deal anyway. > > ...Unless the program is exiting because it's out of memory. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100407/1db8b767/attachment.html> | |||
April 07, 2010 [phobos] Printing exceptions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to David Simcha | The OutOfMemory exception is a special case and doesn't allocate memory in toString or print a stack trace. Sadly, it doesn't even show file and line info. So no worries there. Sent from my iPhone On Apr 7, 2010, at 10:08 AM, David Simcha <dsimcha at gmail.com> wrote: > > > On Wed, Apr 7, 2010 at 1:05 PM, Sean Kelly <sean at invisibleduck.org> > wrote: > I guess some memory allocations and such on exit aren't a big deal > anyway. > > > ...Unless the program is exiting because it's out of memory. > _______________________________________________ > phobos mailing list > phobos at puremagic.com > http://lists.puremagic.com/mailman/listinfo/phobos -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100407/729446a7/attachment.html> | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply