Copyright | (c) Harvard University 2008-2011 (c) Geoffrey Mainland 2011-2016 |
---|---|
License | BSD-style |
Maintainer | mainland@cs.drexel.edu |
Safe Haskell | None |
Language | Haskell98 |
Control.Monad.Exception
Description
Synopsis
- class (Typeable e, Show e) => Exception e where
- toException :: e -> SomeException
- fromException :: SomeException -> Maybe e
- displayException :: e -> String
- data SomeException
- class Monad m => MonadException m where
- onException :: MonadException m => m a -> m b -> m a
- class (MonadIO m, MonadException m) => MonadAsyncException m where
- mask :: ((forall a. m a -> m a) -> m b) -> m b
- bracket :: MonadAsyncException m => m a -> (a -> m b) -> (a -> m c) -> m c
- bracket_ :: MonadAsyncException m => m a -> m b -> m c -> m c
- newtype ExceptionT m a = ExceptionT {
- runExceptionT :: m (Either SomeException a)
- mapExceptionT :: (m (Either SomeException a) -> n (Either SomeException b)) -> ExceptionT m a -> ExceptionT n b
- liftException :: MonadException m => Either SomeException a -> m a
Documentation
class (Typeable e, Show e) => Exception e where #
Minimal complete definition
Nothing
Methods
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
Instances
Exception NestedAtomically | |
Defined in Control.Exception.Base Methods toException :: NestedAtomically -> SomeException # fromException :: SomeException -> Maybe NestedAtomically # displayException :: NestedAtomically -> String # | |
Exception NoMethodError | |
Defined in Control.Exception.Base Methods toException :: NoMethodError -> SomeException # fromException :: SomeException -> Maybe NoMethodError # displayException :: NoMethodError -> String # | |
Exception NonTermination | |
Defined in Control.Exception.Base Methods toException :: NonTermination -> SomeException # fromException :: SomeException -> Maybe NonTermination # displayException :: NonTermination -> String # | |
Exception PatternMatchFail | |
Defined in Control.Exception.Base Methods toException :: PatternMatchFail -> SomeException # fromException :: SomeException -> Maybe PatternMatchFail # displayException :: PatternMatchFail -> String # | |
Exception RecConError | |
Defined in Control.Exception.Base Methods toException :: RecConError -> SomeException # fromException :: SomeException -> Maybe RecConError # displayException :: RecConError -> String # | |
Exception RecSelError | |
Defined in Control.Exception.Base Methods toException :: RecSelError -> SomeException # fromException :: SomeException -> Maybe RecSelError # displayException :: RecSelError -> String # | |
Exception RecUpdError | |
Defined in Control.Exception.Base Methods toException :: RecUpdError -> SomeException # fromException :: SomeException -> Maybe RecUpdError # displayException :: RecUpdError -> String # | |
Exception TypeError | |
Defined in Control.Exception.Base Methods toException :: TypeError -> SomeException # fromException :: SomeException -> Maybe TypeError # displayException :: TypeError -> String # | |
Exception ErrorCall | |
Defined in GHC.Exception Methods toException :: ErrorCall -> SomeException # fromException :: SomeException -> Maybe ErrorCall # displayException :: ErrorCall -> String # | |
Exception ArithException | |
Defined in GHC.Exception.Type Methods toException :: ArithException -> SomeException # fromException :: SomeException -> Maybe ArithException # displayException :: ArithException -> String # | |
Exception SomeException | |
Defined in GHC.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # | |
Exception AllocationLimitExceeded | |
Defined in GHC.IO.Exception Methods toException :: AllocationLimitExceeded -> SomeException # fromException :: SomeException -> Maybe AllocationLimitExceeded # displayException :: AllocationLimitExceeded -> String # | |
Exception ArrayException | |
Defined in GHC.IO.Exception Methods toException :: ArrayException -> SomeException # fromException :: SomeException -> Maybe ArrayException # displayException :: ArrayException -> String # | |
Exception AssertionFailed | |
Defined in GHC.IO.Exception Methods toException :: AssertionFailed -> SomeException # fromException :: SomeException -> Maybe AssertionFailed # displayException :: AssertionFailed -> String # | |
Exception AsyncException | |
Defined in GHC.IO.Exception Methods toException :: AsyncException -> SomeException # fromException :: SomeException -> Maybe AsyncException # displayException :: AsyncException -> String # | |
Exception BlockedIndefinitelyOnMVar | |
Defined in GHC.IO.Exception Methods toException :: BlockedIndefinitelyOnMVar -> SomeException # fromException :: SomeException -> Maybe BlockedIndefinitelyOnMVar # displayException :: BlockedIndefinitelyOnMVar -> String # | |
Exception BlockedIndefinitelyOnSTM | |
Defined in GHC.IO.Exception Methods toException :: BlockedIndefinitelyOnSTM -> SomeException # fromException :: SomeException -> Maybe BlockedIndefinitelyOnSTM # displayException :: BlockedIndefinitelyOnSTM -> String # | |
Exception CompactionFailed | |
Defined in GHC.IO.Exception Methods toException :: CompactionFailed -> SomeException # fromException :: SomeException -> Maybe CompactionFailed # displayException :: CompactionFailed -> String # | |
Exception Deadlock | |
Defined in GHC.IO.Exception Methods toException :: Deadlock -> SomeException # fromException :: SomeException -> Maybe Deadlock # displayException :: Deadlock -> String # | |
Exception IOException | |
Defined in GHC.IO.Exception Methods toException :: IOException -> SomeException # fromException :: SomeException -> Maybe IOException # displayException :: IOException -> String # | |
Exception SomeAsyncException | |
Defined in GHC.IO.Exception Methods toException :: SomeAsyncException -> SomeException # fromException :: SomeException -> Maybe SomeAsyncException # displayException :: SomeAsyncException -> String # | |
Exception ExitCode | |
Defined in GHC.IO.Exception Methods toException :: ExitCode -> SomeException # fromException :: SomeException -> Maybe ExitCode # displayException :: ExitCode -> String # | |
Exception FixIOException | |
Defined in GHC.IO.Exception Methods toException :: FixIOException -> SomeException # fromException :: SomeException -> Maybe FixIOException # displayException :: FixIOException -> String # |
data SomeException #
Instances
Show SomeException | |
Defined in GHC.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS show :: SomeException -> String showList :: [SomeException] -> ShowS | |
Exception SomeException | |
Defined in GHC.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # |
class Monad m => MonadException m where Source #
Methods
throw :: Exception e => e -> m a Source #
Throw an exception.
Arguments
:: Exception e | |
=> m a | The computation to run |
-> (e -> m a) | Handler to invoke if an exception is raised |
-> m a |
Catch an exception.
Arguments
:: m a | The computation to run |
-> m b | Computation to run afterward (even if an exception was raised) |
-> m a |
Run a computation and always perform a second, final computation even
if an exception is raised. If a short-circuiting monad transformer such
as ErrorT or MaybeT is used to transform a MonadException monad, then the
implementation of finally
for the transformed monad must guarantee that
the final action is also always performed when any short-circuiting
occurs.
Instances
Arguments
:: MonadException m | |
=> m a | The computation to run |
-> m b | Computation to run if an exception is raised |
-> m a |
If an exception is raised by the computation, then perform a final action and re-raise the exception.
class (MonadIO m, MonadException m) => MonadAsyncException m where Source #
Methods
mask :: ((forall a. m a -> m a) -> m b) -> m b Source #
Executes a computation with asynchronous exceptions masked. The
argument passed to mask
is a function that takes as its argument
another function, which can be used to restore the prevailing masking
state within the context of the masked computation.
Instances
Arguments
:: MonadAsyncException m | |
=> m a | computation to run first ("acquire resource") |
-> (a -> m b) | computation to run last ("release resource") |
-> (a -> m c) | computation to run in-between |
-> m c |
When you want to acquire a resource, do some work with it, and then release
the resource, it is a good idea to use bracket
, because bracket
will
install the necessary exception handler to release the resource in the event
that an exception is raised during the computation. If an exception is
raised, then bracket
will re-raise the exception (after performing the
release).
bracket_ :: MonadAsyncException m => m a -> m b -> m c -> m c Source #
A variant of bracket
where the return value from the first computation is
not required.
newtype ExceptionT m a Source #
Constructors
ExceptionT | |
Fields
|
Instances
mapExceptionT :: (m (Either SomeException a) -> n (Either SomeException b)) -> ExceptionT m a -> ExceptionT n b Source #
liftException :: MonadException m => Either SomeException a -> m a Source #
Lift the result of running a computation in a monad transformed by
ExceptionT
into another monad that supports exceptions.