Collateral Exceptions, Throwable vs Exception

Sean Kelly sean at invisibleduck.org
Thu Aug 19 15:45:03 PDT 2010


The .next property is to allow chaining.  However, it may be that the current behavior of toString is incorrect, or that a new function should be added that only returns a string describing the current exception and not the entire chain.

Andrej Mitrovic Wrote:

> I think I found the problem. e contains all the collateral exceptions
> (in a linked list according to TDPL), and printing out e will print
> out each and every collateral exception.
> 
> So if that's the case, there's no point to using that while loop. But
> if we can't print out only one exception from a linked list, then what
> is the point of the .next property?
> 
> This prints out the all the collateral exceptions:
> 
>     try
>     {
>         fun();
>     }
>     catch (Throwable e)
>     {
>         writeln(e);
>     }
> 
> 
> 
> On Thu, Aug 19, 2010 at 11:11 PM, Sean Kelly <sean at invisibleduck.org> wrote:
> > Andrej Mitrovic Wrote:
> >
> >> Yes, I've added it as Throwable. But there's one more problem with
> >> your code, this:
> >>
> >> catch (Throwable e)     // have to use Throwable for collateral exceptions
> >>                             // or maybe use a cast like below
> >>     {
> >>         writeln("Primary exception: ", typeid(e), " ", e);
> >>
> >>         while ((e = e.next) !is null)
> >>         {
> >>             writeln("Collateral exception: ", typeid(e), " ", e);
> >>         }
> >>     }
> >>
> >> Will output ~5000 lines of "Exception .." stuff. Oh and in the book it
> >> looks like you're counting from 100 to 1 (for the throws from gun),
> >> which makes sense. Yet I'm getting back output from 1 to 100. Not sure
> >> what's going on there..
> >
> > Are these stack trace lines or actual distinct exceptions?
> >



More information about the Digitalmars-d mailing list