control-monad-exception: Explicitly typed, checked exceptions with stack traces
This package provides explicitly typed, checked exceptions as a library.
Computations throwing different types of exception can be combined seamlessly.
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
In addition to explicitly typed exceptions this package provides:
Support for explicitly documented, unchecked exceptions (via
Control.Monad.Exception.tryEMT
).Support for selective unchecked exceptions (via
Control.Monad.Exception.UncaughtException
).Support for exception call traces via
Control.Monad.Loc.MonadLoc
. Example:
f () = do throw MyException g a = do f a main = runEMT $ do g () `catchWithSrcLoc` \loc (e::MyException) -> lift(putStrLn$ showExceptionWithTrace loc e) -- Running main produces the output: *Main> main MyException in f, Main(example.hs): (1,6) g, Main(example.hs): (2,6) main, Main(example.hs): (5,9) main, Main(example.hs): (4,16)
Modules
[Index] [Quick Jump]
Flags
Automatic Flags
Name | Description | Default |
---|---|---|
extensibleexceptions | Use extensible-exception package | Disabled |
Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info
Downloads
- control-monad-exception-0.11.4.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
Versions [RSS] | 0.1, 0.1.1, 0.1.2, 0.2, 0.3, 0.3.1, 0.3.2, 0.4, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.4.8, 0.5, 0.6, 0.8.0, 0.8.0.1, 0.8.0.2, 0.8.0.3, 0.8.0.4, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.10.3.1, 0.11.1, 0.11.2, 0.11.3, 0.11.4 |
---|---|
Change log | changelog |
Dependencies | base (>=3.0 && <5), extensible-exceptions (>=0.1 && <0.2), failure (>=0.1 && <0.3), lifted-base (>=0.2.1), monad-control (>=0.3), monadloc (>=0.7), transformers (>=0.2), transformers-base (>=0.4.1) [details] |
Tested with | ghc ==8.6.5, ghc ==8.8.3, ghc ==8.10.1 |
License | LicenseRef-PublicDomain |
Author | Pepe Iborra |
Maintainer | pepeiborra@gmail.com |
Category | Control, Monads, Failure |
Home page | http://pepeiborra.github.com/control-monad-exception |
Bug tracker | http://github.com/pepeiborra/control-monad-exception/issues |
Source repo | head: git clone git://github.com/pepeiborra/control-monad-exception.git |
Uploaded | by PepeIborra at 2020-07-06T06:53:51Z |
Distributions | |
Reverse Dependencies | 8 direct, 1106 indirect [details] |
Downloads | 25102 total (75 in the last 30 days) |
Rating | (no votes yet) [estimated by Bayesian average] |
Your Rating | |
Status | Docs available [build log] Last success reported on 2020-07-06 [all 1 reports] |