[phobos] Printing exceptions

Sean Kelly sean at invisibleduck.org
Wed Apr 7 10:05:39 PDT 2010


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.


More information about the phobos mailing list