Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Monad m => MonadException m where
- catchSomeExc :: forall m a. MonadException m => m a -> (Exc m -> m (Maybe a)) -> m a
- fromResultExc :: forall m a. MonadException m => Result (Exc m) a -> m a
- tryExc :: forall m a. MonadException m => m a -> m (Result (Exc m) a)
- onException :: forall m a. MonadException m => m a -> m () -> m a
- catchPureError :: a -> IO (Maybe SomeException)
- mask :: forall m b. MonadTunnelIO m => ((forall a. m a -> m a) -> m b) -> m b
- bracket :: forall m a b. (MonadException m, MonadTunnelIO m) => m a -> (a -> m ()) -> (a -> m b) -> m b
- finally :: forall m a. (MonadException m, MonadTunnelIO m) => m a -> m () -> m a
- bracket_ :: forall m. (MonadException m, MonadTunnelIO m) => m () -> m () -> m --> m
- bracketNoMask :: forall m a b. MonadException m => m a -> (a -> m ()) -> (a -> m b) -> m b
- bracketNoMask_ :: forall m. MonadException m => m () -> m () -> m --> m
- bracketFake :: forall m a b. Monad m => m a -> (a -> m ()) -> (a -> m b) -> m b
- data SomeException
- evaluate :: a -> IO a
Documentation
class Monad m => MonadException m where Source #
Pretty much every monad can be made an instance of this class.
Instances
catchSomeExc :: forall m a. MonadException m => m a -> (Exc m -> m (Maybe a)) -> m a Source #
Catch all exceptions, optionally returning or re-throwing.
fromResultExc :: forall m a. MonadException m => Result (Exc m) a -> m a Source #
tryExc :: forall m a. MonadException m => m a -> m (Result (Exc m) a) Source #
Catch all exceptions as a Result
.
onException :: forall m a. MonadException m => m a -> m () -> m a Source #
Run the handler on exception. Does not mask asynchronous exceptions on the handler.
catchPureError :: a -> IO (Maybe SomeException) Source #
This catches certain "bottom values". Of course, since non-termination is bottom, this cannot catch all bottoms.
mask :: forall m b. MonadTunnelIO m => ((forall a. m a -> m a) -> m b) -> m b Source #
Run with asynchronous exceptions masked, passing an unmask function.
bracket :: forall m a b. (MonadException m, MonadTunnelIO m) => m a -> (a -> m ()) -> (a -> m b) -> m b Source #
Bracket an operation with before and after operations. The whole thing is masked, with the main operation unmasked.
finally :: forall m a. (MonadException m, MonadTunnelIO m) => m a -> m () -> m a Source #
Variant of bracket
.
bracket_ :: forall m. (MonadException m, MonadTunnelIO m) => m () -> m () -> m --> m Source #
Variant of bracket
.
bracketNoMask :: forall m a b. MonadException m => m a -> (a -> m ()) -> (a -> m b) -> m b Source #
Like bracket
, but doesn't mask asynchronous exceptions.
bracketNoMask_ :: forall m. MonadException m => m () -> m () -> m --> m Source #
Variant of bracketNoMask
.
bracketFake :: forall m a b. Monad m => m a -> (a -> m ()) -> (a -> m b) -> m b Source #
Like bracketNoMask
, but doesn't catch any exceptions.
data SomeException #
The SomeException
type is the root of the exception type hierarchy.
When an exception of type e
is thrown, behind the scenes it is
encapsulated in a SomeException
.
Instances
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type | |
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # |
Evaluate the argument to weak head normal form.
evaluate
is typically used to uncover any exceptions that a lazy value
may contain, and possibly handle them.
evaluate
only evaluates to weak head normal form. If deeper
evaluation is needed, the force
function from Control.DeepSeq
may be handy:
evaluate $ force x
There is a subtle difference between
and evaluate
x
,
analogous to the difference between return
$!
xthrowIO
and throw
. If the lazy
value x
throws an exception,
will fail to return an
return
$!
xIO
action and will throw an exception instead.
, on the
other hand, always produces an evaluate
xIO
action; that action will throw an
exception upon execution iff x
throws an exception upon evaluation.
The practical implication of this difference is that due to the imprecise exceptions semantics,
(return $! error "foo") >> error "bar"
may throw either "foo"
or "bar"
, depending on the optimizations
performed by the compiler. On the other hand,
evaluate (error "foo") >> error "bar"
is guaranteed to throw "foo"
.
The rule of thumb is to use evaluate
to force or handle exceptions in
lazy values. If, on the other hand, you are forcing a lazy value for
efficiency reasons only and do not care about exceptions, you may
use
.return
$!
x