[Haskell] Better Exception Handling

Mark Carroll mark at ixod.org
Tue Nov 23 12:46:51 EST 2004

On Tue, 23 Nov 2004, John Goerzen wrote:
> I've been using Haskell for 1-2 months now, and feel fairly comfortable
> catchJust :: (Exception -> Maybe b) -> (c -> a) -> c -> (b -> a) -> a

Yes, this was one of the first things that bothered me, too, when I
started actually writing much Haskell code: I wanted a non-monadic version
of try/catch. Because a pure function should always return the same value
given the same arguments, the behaviour of such a try/catch must be made
quite deterministic: for example, perhaps it should only return exceptions
generated in its own execution thread (to make it entirely synchronous),
and perhaps all the exceptions that could be generated in its evaluation
should be generated (so we don't learn anything about evaluation order -
after the first exception, we may need to carry on evaluating other parts
of the expression to find what other exceptions there are). I seem to have
learned to live with the lack of such non-monadic exceptions: often I use
monads for this sort of error propagation thing, but not the standard
try/catch in the IO monad because I avoid the IO monad wherever possible
because functions in the IO monad are so unconstrained by the type system
with regard to what effects they could have.

-- Mark

More information about the Haskell mailing list