@hackage control-monad-exception0.4.4
Explicitly typed, checked exceptions with stack traces
Installation
Dependencies (7)
- base >=3.0 && <4
- extensible-exceptions >=0.1 && <0.2
- monads-fd >=0.0 && <0.1
- mtl
- pretty
- template-haskell Show all…
Dependents (8)
@hackage/control-monad-exception-mtl, @hackage/safe-failure, @hackage/hs-java, @hackage/acme-everything, @hackage/safe-failure-cme, @hackage/control-monad-exception-monadstf, Show all…
Package Flags
transformers
(on by default)
Use transformers and monads-fd instead of mtl
extensibleexceptions
(off by default)
Use extensible-exception package
This package provides explicitly typed, checked exceptions as a library. Example
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)
data DivideByZero = DivideByZero deriving (Show, Typeable) data SumOverflow = SumOverflow deriving (Show, Typeable)
instance Exception DivideByZero instance Exception SumOverflow
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
New in version 0.4:
Support for unchecked exceptions (with
UncaughtException)Support for exception stack traces (with
WithSrcLoc). Example
f () = $withLocTH $ throw MyException
g a = $withLocTH $ f a
main = runEMT $ $withLocTH $ do
g () `catchWithSrcLoc` \loc MyException ->
lift $ putStrLn (showExceptionWithTrace loc MyException)-- Running @main@ produces the output:
*Main> main
MyException
in Main(example.hs): (12,6)
Main(example.hs): (11,7)