A universal data type for computations which may fail. Errors are reported using extensible exceptions. These exceptions are not explicitly stated; if you want this kind of functionality, something like control-monad-exception might be a more appropriate fit.
- data Attempt v
- class FromAttempt a where
- fa :: FromAttempt a => Attempt v -> a v
- joinAttempt :: (FromAttempt m, Monad m) => m (Attempt v) -> m v
- attempt :: (forall e. Exception e => e -> b) -> (a -> b) -> Attempt a -> b
- makeHandler :: [AttemptHandler v] -> v -> forall e. Exception e => e -> v
- data AttemptHandler v = forall e . Exception e => AttemptHandler (e -> v)
- isFailure :: Attempt v -> Bool
- isSuccess :: Attempt v -> Bool
- fromSuccess :: Attempt v -> v
- successes :: [Attempt v] -> [v]
- failures :: [Attempt v] -> [SomeException]
- partitionAttempts :: [Attempt v] -> ([SomeException], [v])
- attemptIO :: (Exception eIn, Exception eOut) => (eIn -> eOut) -> IO v -> IO (Attempt v)
- module Control.Failure
Data type and type class
Any type which can be converted from an
Attempt. The included instances are your "usual suspects" for dealing with error handling. They include:
General handling of
Process either the exception or value in an
Attempt to produce a result.
This function is modeled after
either. The first argument must
accept any instances of
Exception. If you want to handle multiple types
of exceptions, see
makeHandler. The second argument converts the success
Note that this function does not expose all the data available in an
Attempt value. Notably, the monadic stack trace is not passed on to the
error handler. If desired, use the
monadicStackTrace function to extract
A simple wrapper value necesary due to the Haskell type system. Wraps a
function from a *specific*
Exception type to some value.
This is an unsafe, partial function which should only be used if you either know that a function will succeed or don't mind the occassional runtime exception.
Returns only the
Failure values, each wrapped in a
Catches runtime (ie, IO) exceptions inserts them into an
handle, the first argument to this function must explicitly state the
type of its input.