Handling exceptions
The libraries in this subsection are as follows:
exceptions
: Generalizing extensible extensions to any monad via type-classes (MonadThrow
,MonadCatch
, andMonadMask
)safe-exceptions
: At the time of writing,safe-exceptions
is a recent attempt at pumping more sense into exception handling in the Haskell ecosystem
When working with custom monads and exceptions, it's advisable to use generalized functions from the exceptions library to conveniently throw, catch, and mask exceptions. The functions work pretty much the same as their originals from Control.Exception
, unless somehow restricted by the base monad.
There are a few nuisances in the way exceptions are handled in Haskell and GHC. In particular, differentiating between synchronous and asynchronous exceptions is fickle. Plus, with current exception mechanisms in base, it's easy to make unnecessary mistakes, such as throwing asynchronous exceptions unintentionally (with throw
) or throwing important exceptions away with failing...