catch-fd-0.2.0.2: MonadThrow and MonadCatch, using functional dependencies

Portabilitynon-portable
Stabilityexperimental
MaintainerAndy Sonnenburg <andy22286@gmail.com>
Safe HaskellSafe-Inferred

Control.Monad.Catch.Class

Description

Computation type:
Computations which may fail or throw exceptions; and computations which may catch failures and thrown exceptions.
Binding strategy:
Failure records information about the cause/location of the failure. Failure values bypass the bound function; other values are used as inputs to the bound function (same as MonadError).
Useful for:
Building computations from sequences of functions that may fail; and using exception handling to structure error handling. The handler may or may not throw an exception, which does not have to be of the same type as the original thrown exception (see mapE).
Zero and plus:
Zero is represented by an empty error, and the plus operation executes its second argument if the first fails (same as MonadError).
Example type:
Either String a

The Throw and Catch monads.

Synopsis

Documentation

class Monad m => MonadThrow e m | m -> e whereSource

The strategy of combining computations that can throw exceptions.

Is parameterized over the type of error information and the monad type constructor. It is common to use Either String. In some cases you will have to define an instance of MonadThrow, though rarely a definition of throw

Methods

throw :: e -> m aSource

Is used within a monadic computation to begin exception processing. If (MonadThrow e n, MonadTrans t) => t n ~ m, then throw = lift . throw is the default definition.

Instances

MonadThrow IOException IO 
(Monad (MaybeT m), MonadThrow e m) => MonadThrow e (MaybeT m) 
(Monad (ListT m), MonadThrow e m) => MonadThrow e (ListT m) 
(Monad (IdentityT m), MonadThrow e m) => MonadThrow e (IdentityT m) 
Monad (Either e) => MonadThrow e (Either e) 
(Monad (WrappedMonadCatch m), MonadThrow e m) => MonadThrow e (WrappedMonadCatch m) 
(Monad (WrappedMonadError m), MonadError e m) => MonadThrow e (WrappedMonadError m) 
(Monad (WriterT w m), Monoid w, MonadThrow e m) => MonadThrow e (WriterT w m) 
(Monad (WriterT w m), Monoid w, MonadThrow e m) => MonadThrow e (WriterT w m) 
(Monad (StateT s m), MonadThrow e m) => MonadThrow e (StateT s m) 
(Monad (StateT s m), MonadThrow e m) => MonadThrow e (StateT s m) 
(Monad (ReaderT r m), MonadThrow e m) => MonadThrow e (ReaderT r m) 
(Monad (ErrorT e m), Error e, Monad m) => MonadThrow e (ErrorT e m) 
(Monad (RWST r w s m), Monoid w, MonadThrow e m) => MonadThrow e (RWST r w s m) 
(Monad (RWST r w s m), Monoid w, MonadThrow e m) => MonadThrow e (RWST r w s m) 

class (MonadThrow e m, Monad n) => MonadCatch e m n | n e -> m whereSource

The strategy of combining computations that can handle thrown exceptions, as well as throwing exceptions in the original computation.

Is parameterized over the type of error information and the original monad type constructor, as well as the handler monad type constructor. The handler monad type constructor commonly differs from the original monad type constructor due to a change in the type of the error information.

Methods

catch :: m a -> (e -> n a) -> n aSource

A handler function to handle thrown values and return to normal execution. A common idiom is:

 do { action1; action2; action3 } `catch` handler

where the action functions can call throw. Note that handler and the do-block must have the same return type.

Instances

MonadCatch IOException IO IO 
(MonadThrow e (MaybeT m), Monad (MaybeT n), MonadCatch e m n) => MonadCatch e (MaybeT m) (MaybeT n) 
(MonadThrow e (ListT m), Monad (ListT n), MonadCatch e m n) => MonadCatch e (ListT m) (ListT n) 
(MonadThrow e (IdentityT m), Monad (IdentityT n), MonadCatch e m n) => MonadCatch e (IdentityT m) (IdentityT n) 
(MonadThrow e (Either e), Monad (Either e')) => MonadCatch e (Either e) (Either e') 
(MonadThrow e (WrappedMonadCatch m), Monad (WrappedMonadCatch n), MonadCatch e m n) => MonadCatch e (WrappedMonadCatch m) (WrappedMonadCatch n) 
(MonadThrow e (WrappedMonadError m), Monad (WrappedMonadError m), MonadError e m) => MonadCatch e (WrappedMonadError m) (WrappedMonadError m) 
(MonadThrow e (WriterT w m), Monad (WriterT w n), Monoid w, MonadCatch e m n) => MonadCatch e (WriterT w m) (WriterT w n) 
(MonadThrow e (WriterT w m), Monad (WriterT w n), Monoid w, MonadCatch e m n) => MonadCatch e (WriterT w m) (WriterT w n) 
(MonadThrow e (StateT s m), Monad (StateT s n), MonadCatch e m n) => MonadCatch e (StateT s m) (StateT s n) 
(MonadThrow e (StateT s m), Monad (StateT s n), MonadCatch e m n) => MonadCatch e (StateT s m) (StateT s n) 
(MonadThrow e (ReaderT r m), Monad (ReaderT r n), MonadCatch e m n) => MonadCatch e (ReaderT r m) (ReaderT r n) 
(MonadThrow e (ErrorT e m), Monad (ErrorT e' m), Error e, Error e', Monad m) => MonadCatch e (ErrorT e m) (ErrorT e' m) 
(MonadThrow e (RWST r w s m), Monad (RWST r w s n), Monoid w, MonadCatch e m n) => MonadCatch e (RWST r w s m) (RWST r w s n) 
(MonadThrow e (RWST r w s m), Monad (RWST r w s n), Monoid w, MonadCatch e m n) => MonadCatch e (RWST r w s m) (RWST r w s n) 

mapE :: (MonadCatch e m n, MonadThrow e' n) => (e -> e') -> m a -> n aSource

Map the thrown value using the given function