Source codeContentsIndex
Control.Exception.Generic
PortabilityGHC 6.8
Stabilityexperimental
Maintainertov at ccs dot neu dot edu
Contents
Classes and types
Exception types (re-exported)
Lifting functions
Lots of functions
Filters (re-exported)
Tests
Description

THIS PACKAGE HAS BEEN SUPERSEDED.

For GHC >= 6.10, check out the control-monad-exception package at Hackage at http://hackage.haskell.org/cgi-bin/hackage-scripts/package/control-monad-exception. It does everything this package does and works with the new exception system.

A generalization of exception handling, both inside and outside the IO monad. Based on Oleg Kiselyov's Control.Exception.MonadIO.

In the GHC library, catch has type IO a -> (Exception -> IO a) -> IO a. If you are using monad transformers on top of IO, this means that you can still use liftIO to catch exceptions, but the handler has to be written in the IO monad, not the richer monad that you're working in.

This module provides an API to fix this problem: Simply define an instances of EMonad for your monad transformer, and then use gcatch to catch exceptions and glift rather than lift to faithfully propogate exceptions out of the lifted term.

Synopsis
class Monad m => EMonad m where
gthrow :: Exception -> m a
gcatch :: m a -> (Exception -> m a) -> m a
ghandle :: (Exception -> m a) -> m a -> m a
gtry :: m a -> m (Either Exception a)
class (EMonad m, MonadIO m) => EMonadIO m
glift :: (MonadTrans t, EMonad m, EMonad (t m)) => m a -> t m a
guntry :: EMonad m => Either Exception a -> m a
gthrowStr :: EMonad m => String -> m a
gcatchJust :: EMonad m => (Exception -> Maybe b) -> m a -> (b -> m a) -> m a
ghandleJust :: EMonad m => (Exception -> Maybe b) -> (b -> m a) -> m a -> m a
gtryJust :: EMonad m => (Exception -> Maybe b) -> m b1 -> m (Either b b1)
gignore :: EMonad m => m a -> m ()
gignoreJust :: EMonad m => (Exception -> Maybe b) -> m a -> m ()
gthrowDyn :: (Typeable exc, EMonad m) => exc -> m a
gcatchDyn :: (Typeable exc, EMonad m) => m a -> (exc -> m a) -> m a
ghandleDyn :: (Typeable exc, EMonad m) => (exc -> m a) -> m a -> m a
gtryDyn :: (Typeable exc, EMonad m) => m a -> m (Either exc a)
gbracket :: EMonad m => m a -> (a -> m b) -> (a -> m c) -> m c
gbracket_ :: EMonad m => m a -> m b -> m c -> m c
gfinally :: EMonad m => m a -> m b -> m a
tests__Control_Exception_Generic :: Test
Classes and types
class Monad m => EMonad m where
Minimal complete definition: gthrow, and one of gcatch, ghandle, or gtry. (It turns out to be slightly useful to be able to define in terms of any of these; e.g., for the EMonad Either instance, gtry = Right.)
Methods
gthrow :: Exception -> m a
gcatch :: m a -> (Exception -> m a) -> m a
ghandle :: (Exception -> m a) -> m a -> m a
gtry :: m a -> m (Either Exception a)
show/hide Instances
EMonad IO
EMonad (Either Exception)
EMonad m => EMonad (ListT m)
Monad m => EMonad (ErrorT Exception m)
EMonad m => EMonad (ReaderT r m)
EMonad m => EMonad (StateT s m)
(Monoid w, EMonad m) => EMonad (WriterT w m)
(Monoid w, EMonad m) => EMonad (RWST r w s m)
class (EMonad m, MonadIO m) => EMonadIO m
Convenience class
show/hide Instances
Exception types (re-exported)
Lifting functions
glift :: (MonadTrans t, EMonad m, EMonad (t m)) => m a -> t m a
This is like lift, but it catches exceptions on the inside and lifts them on the outside.
guntry :: EMonad m => Either Exception a -> m a
This is kind of a useful function -- it's the opposite of gtry.
Lots of functions
These are based on the functions in Control.Exception; they all do the things indicated clearly by their types.
gthrowStr :: EMonad m => String -> m a
gcatchJust :: EMonad m => (Exception -> Maybe b) -> m a -> (b -> m a) -> m a
ghandleJust :: EMonad m => (Exception -> Maybe b) -> (b -> m a) -> m a -> m a
gtryJust :: EMonad m => (Exception -> Maybe b) -> m b1 -> m (Either b b1)
gignore :: EMonad m => m a -> m ()
gignoreJust :: EMonad m => (Exception -> Maybe b) -> m a -> m ()
gthrowDyn :: (Typeable exc, EMonad m) => exc -> m a
gcatchDyn :: (Typeable exc, EMonad m) => m a -> (exc -> m a) -> m a
ghandleDyn :: (Typeable exc, EMonad m) => (exc -> m a) -> m a -> m a
gtryDyn :: (Typeable exc, EMonad m) => m a -> m (Either exc a)
This is cool -- it's a gtry variant that only pulls out dynamic exceptions of one type.
gbracket :: EMonad m => m a -> (a -> m b) -> (a -> m c) -> m c
Note that this gbracket does not protect the cleanup code; I contend that it shouldn't, because starting the cleanup again if it throws the first time is almost never the right thing to do.
gbracket_ :: EMonad m => m a -> m b -> m c -> m c
gfinally :: EMonad m => m a -> m b -> m a
Filters (re-exported)
Tests
tests__Control_Exception_Generic :: Test
Test cases. Most of these functions are suffciently constrained by their types that they can't do the wrong thing unless there's something obviously absurd in them.
Produced by Haddock version 2.4.1