exceptions-0.9.0: Extensible optionally-pure exceptions

Copyright(C) Edward Kmett 2013-2015 (c) Google Inc. 2012
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell98

Control.Monad.Catch.Pure

Contents

Description

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!

Synopsis

Transformer

The transformers-style monad transfomer

newtype CatchT m a Source #

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

CatchT 

Fields

Instances

MonadTrans CatchT Source # 

Methods

lift :: Monad m => m a -> CatchT m a #

MonadRWS r w s m => MonadRWS r w s (CatchT m) Source # 
MonadWriter w m => MonadWriter w (CatchT m) Source # 

Methods

writer :: (a, w) -> CatchT m a #

tell :: w -> CatchT m () #

listen :: CatchT m a -> CatchT m (a, w) #

pass :: CatchT m (a, w -> w) -> CatchT m a #

MonadState s m => MonadState s (CatchT m) Source # 

Methods

get :: CatchT m s #

put :: s -> CatchT m () #

state :: (s -> (a, s)) -> CatchT m a #

MonadReader e m => MonadReader e (CatchT m) Source # 

Methods

ask :: CatchT m e #

local :: (e -> e) -> CatchT m a -> CatchT m a #

reader :: (e -> a) -> CatchT m a #

Monad m => Monad (CatchT m) Source # 

Methods

(>>=) :: CatchT m a -> (a -> CatchT m b) -> CatchT m b #

(>>) :: CatchT m a -> CatchT m b -> CatchT m b #

return :: a -> CatchT m a #

fail :: String -> CatchT m a #

Monad m => Functor (CatchT m) Source # 

Methods

fmap :: (a -> b) -> CatchT m a -> CatchT m b #

(<$) :: a -> CatchT m b -> CatchT m a #

MonadFix m => MonadFix (CatchT m) Source # 

Methods

mfix :: (a -> CatchT m a) -> CatchT m a #

Monad m => Applicative (CatchT m) Source # 

Methods

pure :: a -> CatchT m a #

(<*>) :: CatchT m (a -> b) -> CatchT m a -> CatchT m b #

liftA2 :: (a -> b -> c) -> CatchT m a -> CatchT m b -> CatchT m c #

(*>) :: CatchT m a -> CatchT m b -> CatchT m b #

(<*) :: CatchT m a -> CatchT m b -> CatchT m a #

Foldable m => Foldable (CatchT m) Source # 

Methods

fold :: Monoid m => CatchT m m -> m #

foldMap :: Monoid m => (a -> m) -> CatchT m a -> m #

foldr :: (a -> b -> b) -> b -> CatchT m a -> b #

foldr' :: (a -> b -> b) -> b -> CatchT m a -> b #

foldl :: (b -> a -> b) -> b -> CatchT m a -> b #

foldl' :: (b -> a -> b) -> b -> CatchT m a -> b #

foldr1 :: (a -> a -> a) -> CatchT m a -> a #

foldl1 :: (a -> a -> a) -> CatchT m a -> a #

toList :: CatchT m a -> [a] #

null :: CatchT m a -> Bool #

length :: CatchT m a -> Int #

elem :: Eq a => a -> CatchT m a -> Bool #

maximum :: Ord a => CatchT m a -> a #

minimum :: Ord a => CatchT m a -> a #

sum :: Num a => CatchT m a -> a #

product :: Num a => CatchT m a -> a #

(Monad m, Traversable m) => Traversable (CatchT m) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> CatchT m a -> f (CatchT m b) #

sequenceA :: Applicative f => CatchT m (f a) -> f (CatchT m a) #

mapM :: Monad m => (a -> m b) -> CatchT m a -> m (CatchT m b) #

sequence :: Monad m => CatchT m (m a) -> m (CatchT m a) #

MonadIO m => MonadIO (CatchT m) Source # 

Methods

liftIO :: IO a -> CatchT m a #

Monad m => Alternative (CatchT m) Source # 

Methods

empty :: CatchT m a #

(<|>) :: CatchT m a -> CatchT m a -> CatchT m a #

some :: CatchT m a -> CatchT m [a] #

many :: CatchT m a -> CatchT m [a] #

Monad m => MonadPlus (CatchT m) Source # 

Methods

mzero :: CatchT m a #

mplus :: CatchT m a -> CatchT m a -> CatchT m a #

Monad m => MonadMask (CatchT m) Source #

Note: This instance is only valid if the underlying monad has a single exit point!

Methods

mask :: ((forall a. CatchT m a -> CatchT m a) -> CatchT m b) -> CatchT m b Source #

uninterruptibleMask :: ((forall a. CatchT m a -> CatchT m a) -> CatchT m b) -> CatchT m b Source #

generalBracket :: CatchT m a -> (a -> CatchT m ignored1) -> (a -> SomeException -> CatchT m ignored2) -> (a -> CatchT m b) -> CatchT m b Source #

Monad m => MonadCatch (CatchT m) Source # 

Methods

catch :: Exception e => CatchT m a -> (e -> CatchT m a) -> CatchT m a Source #

Monad m => MonadThrow (CatchT m) Source # 

Methods

throwM :: Exception e => e -> CatchT m a Source #

mapCatchT :: (m (Either SomeException a) -> n (Either SomeException b)) -> CatchT m a -> CatchT n b Source #

Map the unwrapped computation using the given function.

runCatchT (mapCatchT f m) = f (runCatchT m)

Typeclass

The mtl style typeclass