Safe Haskell | Safe-Inferred |
---|
It is often useful to distinguish between synchronous and asynchronous exceptions. The common idiom is to run a user-supplied computation catching any synchronous exceptions but allowing asynchronous exceptions (such as user interrupt) pass through.
There's no way to know how — synchronously or asynchronously — an exception was thrown, so we have to work around it by relying on the exception type itself.
This module provides an extensible type for asynchronous exceptions
— SomeAsyncException
— as well as functions for catching synchronous
exceptions.
- data SomeAsyncException
- asyncToException :: Exception e => e -> SomeException
- asyncFromException :: Exception e => SomeException -> Maybe e
- isAsynchronous :: SomeException -> Bool
- catchSync :: IO a -> (SomeException -> IO a) -> IO a
- handleSync :: (SomeException -> IO a) -> IO a -> IO a
- trySync :: IO b -> IO (Either SomeException b)
Documentation
data SomeAsyncException Source
Exception class for asynchronous exceptions.
To mark an exception as asynchronous:
instance Exception MyException where fromException = asyncFromException toException = asyncToException
Note that as of base 4.6, AsyncException
is not yet a subclass of
SomeAsyncException
. Use isAsynchronous
to recognize both
AsyncException
and SomeAsyncException
.
asyncToException :: Exception e => e -> SomeExceptionSource
toException
implementation for asynchronous exceptions
asyncFromException :: Exception e => SomeException -> Maybe eSource
fromException
implementation for asynchronous exceptions
isAsynchronous :: SomeException -> BoolSource
Check whether an exception is asynchronous
catchSync :: IO a -> (SomeException -> IO a) -> IO aSource
Like catch
, but catch any synchronous exceptions; let asynchronous ones pass through
handleSync :: (SomeException -> IO a) -> IO a -> IO aSource
Like handle
, but catch any synchronous exceptions; let asynchronous ones pass through