Portability | non-portable (extended exceptions) |
---|---|

Stability | experimental |

Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |

This is a wrapped version of `Control.Exception`

with types generalized
from `IO`

to all monads in `MonadControlIO`

.

- module Control.Exception
- throwIO :: (MonadIO m, Exception e) => e -> m α
- ioError :: MonadIO m => IOError -> m α
- catch :: (MonadControlIO m, Exception e) => m α -> (e -> m α) -> m α
- catches :: MonadControlIO m => m α -> [Handler m α] -> m α
- data Handler m α = forall e . Exception e => Handler (e -> m α)
- catchJust :: (MonadControlIO m, Exception e) => (e -> Maybe β) -> m α -> (β -> m α) -> m α
- handle :: (MonadControlIO m, Exception e) => (e -> m α) -> m α -> m α
- handleJust :: (MonadControlIO m, Exception e) => (e -> Maybe β) -> (β -> m α) -> m α -> m α
- try :: (MonadControlIO m, Exception e) => m α -> m (Either e α)
- tryJust :: (MonadControlIO m, Exception e) => (e -> Maybe β) -> m α -> m (Either β α)
- evaluate :: MonadIO m => α -> m α
- mask :: MonadControlIO m => ((forall α. m α -> m α) -> m β) -> m β
- mask_ :: MonadControlIO m => m α -> m α
- uninterruptibleMask :: MonadControlIO m => ((forall α. m α -> m α) -> m β) -> m β
- uninterruptibleMask_ :: MonadControlIO m => m α -> m α
- getMaskingState :: MonadIO m => m MaskingState
- bracket :: MonadControlIO m => m α -> (α -> m β) -> (α -> m γ) -> m γ
- bracket_ :: MonadControlIO m => m α -> m β -> m γ -> m γ
- bracketOnError :: MonadControlIO m => m α -> (α -> m β) -> (α -> m γ) -> m γ
- finally :: MonadControlIO m => m α -> m β -> m α
- onException :: MonadControlIO m => m α -> m β -> m α

# Documentation

module Control.Exception

# Throwing exceptions

# Catching exceptions

## The `catch`

functions

:: (MonadControlIO m, Exception e) | |

=> m α | The computation to run |

-> (e -> m α) | Handler to invoke if an exception is raised |

-> m α |

Generalized version of `catch`

.

catches :: MonadControlIO m => m α -> [Handler m α] -> m αSource

Generalized version of `catches`

.

:: (MonadControlIO m, Exception e) | |

=> (e -> Maybe β) | Predicate to select exceptions |

-> m α | Computation to run |

-> (β -> m α) | Handler |

-> m α |

Generalized version of `catchJust`

.

## The `handle`

functions

handle :: (MonadControlIO m, Exception e) => (e -> m α) -> m α -> m αSource

Generalized version of `handle`

.

handleJust :: (MonadControlIO m, Exception e) => (e -> Maybe β) -> (β -> m α) -> m α -> m αSource

Generalized version of `handleJust`

.

## The `try`

functions

tryJust :: (MonadControlIO m, Exception e) => (e -> Maybe β) -> m α -> m (Either β α)Source

Generalized version of `tryJust`

.

## The `evaluate`

function

# Asynchronous Exceptions

## Asynchronous exception control

The following functions allow a thread to control delivery of asynchronous exceptions during a critical region.

mask :: MonadControlIO m => ((forall α. m α -> m α) -> m β) -> m βSource

Generalized version of `mask`

.

mask_ :: MonadControlIO m => m α -> m αSource

Generalized version of `mask_`

.

uninterruptibleMask :: MonadControlIO m => ((forall α. m α -> m α) -> m β) -> m βSource

Generalized version of `uninterruptibleMask`

.

uninterruptibleMask_ :: MonadControlIO m => m α -> m αSource

Generalized version of `uninterruptibleMask_`

.

getMaskingState :: MonadIO m => m MaskingStateSource

Generalized version of `getMaskingState`

.

# Brackets

:: MonadControlIO m | |

=> m α | computation to run first ("acquire resource") |

-> (α -> m β) | computation to run last ("release resource") |

-> (α -> m γ) | computation to run in-between |

-> m γ |

:: MonadControlIO m | |

=> m α | computation to run first ("acquire resource") |

-> m β | computation to run last ("release resource") |

-> m γ | computation to run in-between |

-> m γ |

Generalized version of `bracket_`

. Note, any monadic side
effects in `m`

of *both* the "acquire" and "release"
computations will be discarded. To keep the monadic side effects
of the "acquire" computation, use `bracket`

with constant
functions instead.

Note that when your `acquire`

and `release`

computations are of type `IO`

it will be more efficient to write:

`liftIOOp_`

(`bracket_`

acquire release)

:: MonadControlIO m | |

=> m α | computation to run first ("acquire resource") |

-> (α -> m β) | computation to run last ("release resource") |

-> (α -> m γ) | computation to run in-between |

-> m γ |

Generalized version of `bracketOnError`

. Note, any monadic side
effects in `m`

of the "release" computation will be discarded.

Note that when your `acquire`

and `release`

computations are of type `IO`

it will be more efficient to write:

`liftIOOp`

(`bracketOnError`

acquire release)

# Utilities

:: MonadControlIO m | |

=> m α | computation to run first |

-> m β | computation to run afterward (even if an exception was raised) |

-> m α |

Generalized version of `finally`

. Note, any monadic side
effects in `m`

of the "afterward" computation will be discarded.

onException :: MonadControlIO m => m α -> m β -> m αSource

Generalized version of `onException`

. Note, any monadic side
effects in `m`

of the "afterward" computation will be discarded.