[phobos] Exception chaining

Sean Kelly sean at invisibleduck.org
Tue Jan 11 14:36:21 PST 2011


On Jan 11, 2011, at 1:57 AM, Don Clugston wrote:
> 
> So the general scheme appears to work.
> But, there's something I'm unclear about. When should chained
> exceptions be catchable?
> They are very nasty creatures, and you really want to know when they happen.
> Presumably, an AssertError which occurs while processing an
> FileException, should not be silently chained
> and caught in the FileException.
> In fact, should a chain containing an Error be catchable at all?

Tricky question.  According to TDPL, this is all collateral damage, so I'd expect the chain to be caught just fine.  Worse is something like this:

void fnA() nothrow {
    try {
        fnB(); // documented to throw OopsException
    } catch (OopsException e) {}
}

void fnB() {
    scope(exit) closeFile();
    throw new OopsException;
}

void closeFile() {
    throw new UnableToCloseFileException;
}

Is this code correct or does it violate the nothrow guarantee?


More information about the phobos mailing list