Collateral Exceptions, Throwable vs Exception

Sean Kelly sean at invisibleduck.org
Thu Aug 19 14:20:55 PDT 2010


Andrej Mitrovic 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?

You should avoid explicitly catching Throwable, but I can see what you're getting at: if a collateral exception is an Error then it should not be ignored.  You could always do something like this:

catch (Exception e) {
    for (Throwable t = e; t; t = t.next) {
        if (cast(Error) t)
            throw t; // collateral damage critical!
        writeln(t);
    }
}


More information about the Digitalmars-d mailing list