[Haskell-cafe] Catching string from error function with GHC
Control.Exception
Iain Alexander
ia at stryx.demon.co.uk
Mon Jan 2 20:29:47 EST 2006
I've just been through the process of converting some code from using Control.Exception to
using an Error monad, and I would recommend that as a more straightforward and
manageable alternative, unless you need Control.Exception for other reasons.
I started by changing my potentially-failing functions to return Either Exception a,
where Exception is my own user-defined error type, but you could use String, and a is the
type of the "real" return value. I initially used explicit Left and Right to construct appropriate
values. My testing code is hand-written, and explicitly matched against Left e and Right x to
decode the return value.
I ended up with functions returning MonadError Exception m => m a, using throwError and
return to construct appropriate values. My testing code uses
ErrorT Exception (StateT s IO) a
to manage a combination of error-handling, state (an error count) and IO, with the option of
using Either Exception to test expected errors for individual cases.
--
Iain Alexander ia at stryx.demon.co.uk
More information about the Haskell-Cafe
mailing list