Control.Monad.Error.Class
- Package
- purescript-transformers
- Repository
- purescript/purescript-transformers
This module defines the MonadError
type class and its instances.
#MonadThrow Source
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
MonadThrow e (Either e)
MonadThrow Unit Maybe
#MonadError Source
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
MonadError e (Either e)
MonadError Unit Maybe
#catchJust Source
catchJust :: forall b a m e. 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 a m e. MonadError e m => m a -> m (Either e a)
Return Right
if the given action succeeds, Left
if it throws.
#withResource Source
withResource :: forall a r m e. 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.
- 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. 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