Proposal: Extensible exceptions

David Roundy droundy at
Wed Jul 9 10:42:53 EDT 2008

On Wed, Jul 09, 2008 at 04:17:25PM +0200, Henning Thielemann wrote:
> There is also another unintended application: Escaping from loops or deep 
> recursions, maybe even returning a result by an exception. Actually, in 
> order to define the interaction of abort mechanisms like RETURN in a 
> PROCEDURE or EXIT in LOOP, the Modula-3 designers defined RETURN and EXIT 
> in terms of exceptions (although they suggested to implement them more 
> efficiently). These abuses of exceptions made Niklaus Wirth, the inventor 
> of Pascal, fear, that exceptions bring back a GOTO into structured 
> programming languages.

Incidentally, the Haskell standard libraries (although not the report) also
implement exitWith in terms of an exception.  Personally, I think this is a
great idea, as I'd rather not deal with two separate mechanisms for
cleaning up in unexpected cases (i.e. bugs or exceptions or being passed a
function that calls exitWith).  Having one exception-handling mechanism
allows for modular programming, e.g. I can write a function of type

doSomethingThatMightRequireFreeingResources :: ... -> IO a -> IO a

rather than requiring some sort of weird trickery to figure out all the
possible ways that my argument might possible fail to return so that I can
free whatever resources I need to free.


More information about the Libraries mailing list