| Safe Haskell | Safe |
|---|
LIO.MonadCatch
Description
This module generalizes throw and catch (from Control.Exception)
to methods that can be defined on multiple monads.
- class Monad m => MonadCatch m where
- mask :: ((forall a. m a -> m a) -> m b) -> m b
- mask_ :: m a -> m a
- throwIO :: Exception e => e -> m a
- catch :: Exception e => m a -> (e -> m a) -> m a
- handle :: Exception e => (e -> m a) -> m a -> m a
- onException :: m a -> m b -> m a
- bracket :: m b -> (b -> m c) -> (b -> m a) -> m a
- bracket_ :: m a -> m b -> m c -> m c
- finally :: m a -> m b -> m a
- genericBracket :: MonadCatch m => (m b -> m c -> m b) -> m a -> (a -> m c) -> (a -> m b) -> m b
Documentation
class Monad m => MonadCatch m whereSource
MonadCatch is the class used to generalize the standard IO
catch and throwIO functions to methods that can be defined in
multiple monads.
Minimal definition requires: mask, throwIO, catch, and
onException.
Methods
Arguments
| :: ((forall a. m a -> m a) -> m b) | Function that takes a mask-restoring function as argument and returns an action to execute. |
| -> m b |
Executes a computation with asynchronous exceptions masked. See Control.Exception for more details.
Like mask, but does not pass a restore action to the argument.
throwIO :: Exception e => e -> m aSource
A variant of throwIO that can be used within the monad.
Arguments
| :: Exception e | |
| => m a | Computation to run |
| -> (e -> m a) | Handler |
| -> m a |
Simplest exception-catching function.
handle :: Exception e => (e -> m a) -> m a -> m aSource
Version of catch with the arguments swapped around.
Arguments
| :: m a | Computation to run first |
| -> m b | Computation to run after, if an exception was raised. |
| -> m a |
Performs an action and a subsequent action if an exceptino is raised.
Arguments
| :: m b | Computation to run first |
| -> (b -> m c) | Computation to run last |
| -> (b -> m a) | Computation to run in-between |
| -> m a |
This function allows you to execute an action with an initial
"acquire resource" and final "release resource" as bracket
of Control.Exception.
bracket_ :: m a -> m b -> m c -> m cSource
Variant of bracket where the return value from the first
computation is not required.
Arguments
| :: m a | Computation to run first |
| -> m b | Computation to run after |
| -> m a |
Performs an action and a subsequent action.
Instances
| MonadCatch IO | |
| LabelState l p s => MonadCatch (LIO l p s) |
Arguments
| :: MonadCatch m | |
| => (m b -> m c -> m b) | On exception function |
| -> m a | Action to perform first |
| -> (a -> m c) | Action to perform last |
| -> (a -> m b) | Action to perform in-between |
| -> m b | Result of in-between action |
Given some general onException function, genericBracket
allows you to execute an action with an initial "acquire resource"
and final "release resource" as bracket of Control.Exception.