The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use Either String as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the MonadError class.
You can also define your own error type and/or use a monad type constructor
other than Either or StringEither .
In these cases you will have to explicitly define instances of the MonadError
class.
(If you are using the deprecated IOErrorControl.Monad.Error or
Control.Monad.Trans.Error, you may also have to define an Error instance.)
Methods
throwError :: e -> m aIs used within a monadic computation to begin exception processing.
catchError :: m a -> (e -> m a) -> m aA handler function to handle previous errors and return to normal execution. A common idiom is:
do { action1; action2; action3 } `catchError` handlerwhere the
actionfunctions can call throwError. Note thathandlerand the do-block must have the same return type.
Instances16MonadError, …
MonadError IOException IODefined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError () MaybeDefined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError e (Either e)Defined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError e m => MonadError e (MaybeT m)Defined in mtl-2.3.1 · Control.Monad.Error.ClassMonad m => MonadError e (ExceptT e m)Defined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError e m => MonadError e (IdentityT m)Defined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError e m => MonadError e (ReaderT r m)Defined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError e m => MonadError e (StateT s m)Defined in mtl-2.3.1 · Control.Monad.Error.ClassMonadError e m => MonadError e (StateT s m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (AccumT w m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (WriterT w m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (WriterT w m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (WriterT w m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (RWST r w s m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (RWST r w s m)Defined in mtl-2.3.1 · Control.Monad.Error.Class(Monoid w, MonadError e m) => MonadError e (RWST r w s m)Defined in mtl-2.3.1 · Control.Monad.Error.Class