[Haskell] Better Exception Handling

Peter Strand peter at zarquon.se
Tue Nov 23 17:41:27 EST 2004

John Goerzen wrote:
>>>Python can work that way, but also adds another feature:
>>>    blah
>>>    moreblah
>>>    foo
>>And in Haskell we have catch(Dyn), bracket, and finally. Are these not
> I hadn't been aware of finally.  That does seem to help.

One of the things I like about exceptions in haskell is that there's
relatively little magic, if a function like finally isn't there, you
can implement it yourself.

m `finally` f = do
     r <- m `catch` (\e -> f >> throw e)
     return r

(I'm ignoring asynchronous exceptions for now, see the code for
  Control.Exception for details)

And I find bracket quite useful, it nicely captures a concept you have
to code "by hand" in many other languages. And bracket is also a
function you could have implemented yourself, if it hadn't been


More information about the Haskell mailing list