[Haskell-cafe] Absolutely confused with error/exception handling

Chris Wong lambda.fairy at gmail.com
Sat Dec 17 05:05:45 UTC 2016

> The type signature for catch is --
> catch :: Exception e => IO a -> (e -> IO a) -> IO a
> This is Spock's monad:
> https://hackage.haskell.org/package/Spock-core-
> (it has MonadTrans, MonadIO, Monad, Functor, Applicative, Alternative
> instances).
> How do I catch an exception coming out of an action in the ActionCtxT monad?

The problem is: ActionCtxT includes a custom error system, which is
orthogonal to that provided by exceptions. So to handle exceptions in
such a monad, you'd need to bend over backwards to make these two
systems work together. To be honest I'm not even sure if this is
possible, at least in a way that doesn't have surprising edge cases.

My recommendation is to catch the exception in IO first, before it is
lifted into the ActionCtxT. If your business logic is decoupled from
the web framework (as it should be) then it should be easy enough to
do this.

Chris Wong (https://lambda.xyz)

"I had not the vaguest idea what this meant and when I could not
remember the words, my tutor threw the book at my head, which did not
stimulate my intellect in any way." -- Bertrand Russell

More information about the Haskell-Cafe mailing list