HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleexceptions-0.10.9Haskell2010

Control.Monad.Catch.Pure

This module supplies a 'pure' monad transformer that can be used for mock-testing code that throws exceptions, so long as those exceptions are always thrown with throwM.

Do not mix CatchT with IO. Choose one or the other for the bottom of your transformer stack!

  • 2 types
  • 2 values

Transformer

4 declarations

The transformers-style monad transfomer

newtypenewtype CatchT (m :: Type -> Type) a
#

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:

Example1 expression
(error "Hello!" :: IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)Hello!
Example1 expression
runCatchT $ (error "Hello!" :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)*** Exception: Hello!
Example1 expression
runCatchT $ (throwM (ErrorCall "Hello!") :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)Hello!

Constructors

Instances18MonadTrans, MonadRWS, MonadReader, MonadState, MonadWriter, Monad, …

Typeclass

0 declarations

The mtl style typeclass