[phobos] Exception chaining

Don Clugston dclugston at googlemail.com
Tue Jan 11 01:57:57 PST 2011


I believe I have got TDPL exception chaining working correctly using
Windows Structured Exception Handling.
(This was far from easy!)
Central to making chaining work correctly, is that chaining must only occur
when a collision occurs (not merely when two exceptions are in flight,
because one may be caught before it has any effect on the other). This
means that multiple chains of exceptions
may be in flight at any given time.
My code works in all nasty corner cases I've tested, including
multi-level collisions,
where two exceptions collide in a function, then collide again with an
even earlier exception chain in a finally block in a different function.

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?
(If not, it still has to at least be catchable in the catchall handler
that wraps main()).
Many other schemes are possible, but I think it's important that the
rules remain simple.

One simple solution would be to make chained exceptions only catchable
by catch(Throwable).


More information about the phobos mailing list