Add Exception handling abilities to a Monad.
This should never be used in combination with IO. Think of CatchT as an alternative base monad for use with mocking code that solely throws exceptions via throwM.
Note: that IO monad has these abilities already, so stacking CatchT on top of it does not add any value and can possibly be confusing:
(error "Hello!" :: IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)Hello!
runCatchT $ (error "Hello!" :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)*** Exception: Hello!
runCatchT $ (throwM (ErrorCall "Hello!") :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)Hello!
Constructors
CatchTrunCatchT :: m (Either SomeException a)
Instances18MonadTrans, MonadRWS, MonadReader, MonadState, MonadWriter, Monad, …
MonadTrans CatchTDefined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadRWS r w s m => MonadRWS r w s (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadReader e m => MonadReader e (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadState s m => MonadState s (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadWriter w m => MonadWriter w (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Monad (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Functor (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadFix m => MonadFix (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => MonadFail (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Applicative (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureFoldable m => Foldable (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.Pure(Monad m, Traversable m) => Traversable (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Alternative (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => MonadPlus (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadIO m => MonadIO (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => MonadCatch (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => MonadMask (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureNote: This instance is only valid if the underlying monad has a single exit point!
For example,
IOorEitherwould be invalid base monads, butReaderorStatewould be acceptable.Monad m => MonadThrow (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.Pure