Proposal: Extensible exceptions

David Menendez dave at
Sun Jul 6 13:34:30 EDT 2008

On Sun, Jul 6, 2008 at 6:07 AM, Yitzchak Gale <gale at> wrote:
> David Menendez wrote:
>> I have the guts of an extensible exception library modeled on Simon
>> Marlow's paper that can coexist with the current Control.Exception
>> regime. That is, exceptions thrown by "old" code can be caught by
>> "new" code, and vice versa.
> Nice. It looks like this addition would allow code that only mentions
> old exception constructors to keep working, but it would still
> break code that mentions old exception types. Is this correct?

My implementation doesn't touch Control.Exception at all, so existing
code would still work unmodified. The new throw and catch are in a
different module, and everything else is exactly the way it was
before. The clever part is that the new code can throw a new version
of a pre-existing exception, e.g. DivByZero, and existing code which
is looking for (ArithException DivByZero) will still catch it, and
vice versa, without changing or even recompiling the old code.

I implemented the new exceptions on top of the current ones because I
didn't want to mess around with GHC's internals. It's possible to
implement extensible exceptions in GHC while still fully supporting
the existing Control.Exception interface. The idea is to re-implement
Old.throw and Old.catch in terms of New.throw and New.catch. (In
contrast, my code implements New.throw and New.catch in terms of
Old.throw and Old.catch.)

The hard part is coming up with a new module name, since
Control.Exception is taken.

Dave Menendez <dave at>

More information about the Libraries mailing list