Collateral Exceptions, Throwable vs Exception

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Aug 19 13:25:38 PDT 2010


Actually, would this be safe to use? :

    try
    {
        fun();
    }
    catch (Exception e)
    {
        writeln("Primary exception: ", typeid(e));

        while ((e = cast(Exception)e.next) !is null)
        {
            writeln("Collateral exception: ", typeid(e));
        }
    }



On Thu, Aug 19, 2010 at 10:18 PM, Andrej Mitrovic <
andrej.mitrovich at gmail.com> wrote:

> That goes against the statement in TDPL that user code should never catch
> Throwable's, unless absolutely necessary. So in case of collateral
> exceptions, we are forced to catch Throwable anyway?
>
>
> On Thu, Aug 19, 2010 at 10:00 PM, Sean Kelly <sean at invisibleduck.org>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.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100819/ae084122/attachment.html>


More information about the Digitalmars-d mailing list