Control.Monad.Error.Class
- Package
- purescript-transformers
- Repository
- purescript/purescript-transformers
This module defines the MonadError
type class and its instances.
#MonadThrow Source
class MonadThrow :: Type -> (Type -> Type) -> Constraint
class (Monad m) <= MonadThrow e m | m -> e where
The MonadThrow
type class represents those monads which support errors via
throwError
, where throwError e
halts, yielding the error e
.
An implementation is provided for ExceptT
, and for other monad transformers
defined in this library.
Laws:
- Left zero:
throwError e >>= f = throwError e
Members
throwError :: forall a. e -> m a
Instances
#MonadError Source
class MonadError :: Type -> (Type -> Type) -> Constraint
class (MonadThrow e m) <= MonadError e m | m -> e where
The MonadError
type class represents those monads which support catching
errors.
catchError x f
calls the error handlerf
if an error is thrown during the evaluation ofx
.
An implementation is provided for ExceptT
, and for other monad transformers
defined in this library.
Laws:
- Catch:
catchError (throwError e) f = f e
- Pure:
catchError (pure a) f = pure a
Members
catchError :: forall a. m a -> (e -> m a) -> m a
Instances
#catchJust Source
catchJust :: forall e m a b. MonadError e m => (e -> Maybe b) -> m a -> (b -> m a) -> m a
This function allows you to provide a predicate for selecting the exceptions that you're interested in, and handle only those exceptons. If the inner computation throws an exception, and the predicate returns Nothing, then the whole computation will still fail with that exception.
#try Source
try :: forall e m a. MonadError e m => m a -> m (Either e a)
Return Right
if the given action succeeds, Left
if it throws.
#withResource Source
withResource :: forall e m r a. MonadError e m => m r -> (r -> m Unit) -> (r -> m a) -> m a
Make sure that a resource is cleaned up in the event of an exception. The release action is called regardless of whether the body action throws or returns.
#liftMaybe Source
liftMaybe :: forall m e a. MonadThrow e m => e -> Maybe a -> m a
Lift a Maybe
value to a MonadThrow monad.
#liftEither Source
liftEither :: forall m e a. MonadThrow e m => Either e a -> m a
Lift an Either
value to a MonadThrow monad.
- Modules
- Control.
Comonad. Env - Control.
Comonad. Env. Class - Control.
Comonad. Env. Trans - Control.
Comonad. Store - Control.
Comonad. Store. Class - Control.
Comonad. Store. Trans - Control.
Comonad. Traced - Control.
Comonad. Traced. Class - Control.
Comonad. Traced. Trans - Control.
Comonad. Trans. Class - Control.
Monad. Cont - Control.
Monad. Cont. Class - Control.
Monad. Cont. Trans - Control.
Monad. Error. Class - Control.
Monad. Except - Control.
Monad. Except. Trans - Control.
Monad. Identity. Trans - Control.
Monad. List. Trans - Control.
Monad. Maybe. Trans - Control.
Monad. RWS - Control.
Monad. RWS. Trans - Control.
Monad. Reader - Control.
Monad. Reader. Class - Control.
Monad. Reader. Trans - Control.
Monad. State - Control.
Monad. State. Class - Control.
Monad. State. Trans - Control.
Monad. Trans. Class - Control.
Monad. Writer - Control.
Monad. Writer. Class - Control.
Monad. Writer. Trans