|
Control.Monad.Exception.Base |
|
|
Description |
A Monad Transformer for explicitly typed checked exceptions.
The exceptions thrown by a computation are inferred by the typechecker
and appear in the type signature of the computation as Throws constraints.
Exceptions are defined using the extensible exceptions framework of Marlow (documented in Control.Exception):
- An Extensible Dynamically-Typed Hierarchy of Exceptions, by Simon Marlow, in Haskell '06.
Example
data DivideByZero = DivideByZero deriving (Show, Typeable)
data SumOverflow = SumOverflow deriving (Show, Typeable)
instance Exception DivideByZero
instance Exception SumOverflow
data Expr = Add Expr Expr | Div Expr Expr | Val Double
eval (Val x) = return x
eval (Add a1 a2) = do
v1 <- eval a1
v2 <- eval a2
let sum = v1 + v2
if sum < v1 || sum < v2 then throw SumOverflow else return sum
eval (Div a1 a2) = do
v1 <- eval a1
v2 <- eval a2
if v2 == 0 then throw DivideByZero else return (v1 / v2)
GHCi infers the following types
eval :: (Throws DivideByZero l, Throws SumOverflow l) => Expr -> EM l Double
eval `catch` \ (e::DivideByZero) -> return (-1) :: Throws SumOverflow l => Expr -> EM l Double
runEM(eval `catch` \ (e::SomeException) -> return (-1))
:: Expr -> Double
|
|
Synopsis |
|
|
|
Documentation |
|
|
|
|
A Monad Transformer for explicitly typed checked exceptions.
| Constructors | | Instances | |
|
|
|
|
|
Run a computation explicitly handling exceptions
|
|
|
|
|
Instances | |
|
|
|
|
|
Run a safe computation
|
|
|
Run a safe computation checking even unchecked (UncaughtException) exceptions
|
|
|
The throw primitive
|
|
|
Rethrow an exception keeping the call trace
|
|
|
The catch primitive
|
|
|
Like catch but makes the call trace available
|
|
|
Sequence two computations discarding the result of the second one.
If the first computation rises an exception, the second computation is run
and then the exception is rethrown.
|
|
|
Like finally, but performs the second computation only when the first one
rises an exception
|
|
|
:: Monad m | | => EMT l m a | release resource
| -> a -> EMT l m b | computation
| -> a -> EMT l m c | | -> EMT l m c | |
|
|
|
Capture an exception e, wrap it, and rethrow.
Keeps the original monadic call trace.
|
|
|
|
|
Uncaught Exceptions model unchecked exceptions
In order to declare an unchecked exception E,
all that is needed is to make e an instance of UncaughtException
instance UncaughtException E
Note that declaring an exception E as unchecked does not automatically
turn its children as unchecked too. This is a shortcoming of the current encoding.
If that is what you want, then declare E as unchecked and unexplicit
using an instance of Throws:
instance Throws E l
| | Instances | |
|
|
|
A monad of explicitly typed, checked exceptions
|
|
|
Run a computation explicitly handling exceptions
|
|
|
Run a safe computation
|
|
|
Run a computation checking even unchecked (UncaughtExceptions) exceptions
|
|
|
Constructors | | Instances | |
|
|
|
FailException is thrown by Monad fail
| Constructors | | Instances | |
|
|
data MonadZeroException | Source |
|
MonadZeroException is thrown by MonadPlus mzero
| Constructors | | Instances | |
|
|
|
This function may be used as a value for mplus in MonadPlus
|
|
|
|
Produced by Haddock version 2.6.0 |