attempt-0.0.0: Error handling using extensible exceptions outside the IO monad.Source codeContentsIndex
Control.Monad.Attempt.Class
Description
Defines a type class for any monads which may report failure using extensible exceptions.
Synopsis
class Monad m => MonadAttempt m where
failure :: Exception e => e -> m v
failureString :: String -> m v
wrapFailure :: Exception eOut => (forall eIn. Exception eIn => eIn -> eOut) -> m v -> m v
newtype StringException = StringException String
Documentation
class Monad m => MonadAttempt m whereSource

Any Monad which may report failure using extensible exceptions. This most obviously applies to the Attempt data type, but you should just as well use this for arbitrary Monads.

Usage should be straight forward: return successes and failure errors. If you simply want to send a string error message, use failureString. Although tempting to do so, fail is *not* used as a synonym for failureString; fail should not be used at all.

Minimal complete definition: failure and wrapFailure.

Methods
failure :: Exception e => e -> m vSource
failureString :: String -> m vSource
Call failure by wrapping the argument in a StringException.
wrapFailure :: Exception eOut => (forall eIn. Exception eIn => eIn -> eOut) -> m v -> m vSource
Wrap the failure value, if any, with the given function. This is useful in particular when you want all the exceptions returned from a certain library to be of a certain type, even if they were generated by a different library.
show/hide Instances
newtype StringException Source
A simple exception which simply contains a string. Note that the Show instance simply returns the contained string.
Constructors
StringException String
show/hide Instances
Produced by Haddock version 2.6.0