Collateral Exceptions, Throwable vs Exception

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Aug 19 13:45:05 PDT 2010


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..

On Thu, Aug 19, 2010 at 10:32 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> On 08/19/2010 03:00 PM, Sean Kelly wrote:
>>
>> Andrej Mitrovic Wrote:
>>
>>> TDPL code that should work:
>>
>> ...
>>>
>>> Errors out:
>>> (49): Error: cannot implicitly convert expression (e.next) of type
>>> object.Throwable to object.Exception
>>>
>>> Why would the return type of e.next be Throwable if e is an Exception
>>> type?
>>
>> Because e.next is a Throwable reference inherited from Throwable:
>>
>> class Throwable {
>>     Throwable next;
>> }
>>
>> class Error : Throwable {}
>> class Exception : Throwable {}
>>
>> Because collateral exceptions could be both Errors and Exceptions, I don't
>> think the sample code can work exactly as written.
>
> Sean's right. And thanks Sean and Walter for implementing the exceptions
> spec properly, I believe it's very important to the success of D.
>
> Andrej... sounds like another errata entry, please :o).
>
>
> Andrei
>


More information about the Digitalmars-d mailing list