Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- throwM :: forall e m a. (Exception e, MonadThrow m, HasCallStack) => e -> m a
- throwString :: forall m a. (MonadThrow m, HasCallStack) => String -> m a
- fromJustNoteM :: forall m a. (MonadThrow m, HasCallStack) => String -> Maybe a -> m a
- impossible :: forall m a. (MonadThrow m, HasCallStack) => m a
- catch :: forall e m a. (Exception e, MonadCatch m, HasCallStack) => m a -> (e -> m a) -> m a
- catchJust :: forall e b m a. (Exception e, MonadCatch m, HasCallStack) => (e -> Maybe b) -> m a -> (b -> m a) -> m a
- catches :: forall m a. (MonadCatch m, HasCallStack) => m a -> [ExceptionHandler m a] -> m a
- try :: forall e m a. (Exception e, MonadCatch m, HasCallStack) => m a -> m (Either e a)
- tryJust :: forall e b m a. (Exception e, MonadCatch m, HasCallStack) => (e -> Maybe b) -> m a -> m (Either b a)
- withException :: forall e a m b. (Exception e, MonadCatch m, HasCallStack) => m a -> (e -> m b) -> m a
- checkpoint :: (HasCallStack, MonadCatch m) => Annotation -> m a -> m a
- checkpointMany :: (MonadCatch m, HasCallStack) => [Annotation] -> m a -> m a
- checkpointCallStack :: forall m a. (MonadCatch m, HasCallStack) => m a -> m a
- class Monad m => MonadThrow (m :: Type -> Type)
- class MonadThrow m => MonadCatch (m :: Type -> Type)
- class MonadCatch m => MonadMask (m :: Type -> Type)
- module Freckle.App.Exception.Types
Documentation
throwM :: forall e m a. (Exception e, MonadThrow m, HasCallStack) => e -> m a Source #
throwString :: forall m a. (MonadThrow m, HasCallStack) => String -> m a Source #
fromJustNoteM :: forall m a. (MonadThrow m, HasCallStack) => String -> Maybe a -> m a Source #
impossible :: forall m a. (MonadThrow m, HasCallStack) => m a Source #
catch :: forall e m a. (Exception e, MonadCatch m, HasCallStack) => m a -> (e -> m a) -> m a Source #
catchJust :: forall e b m a. (Exception e, MonadCatch m, HasCallStack) => (e -> Maybe b) -> m a -> (b -> m a) -> m a Source #
:: forall m a. (MonadCatch m, HasCallStack) | |
=> m a | Action to run |
-> [ExceptionHandler m a] | Recovery actions to run if the first action throws an exception
with a type of either |
-> m a |
:: forall e m a. (Exception e, MonadCatch m, HasCallStack) | |
=> m a | Action to run |
-> m (Either e a) | Returns |
:: forall e b m a. (Exception e, MonadCatch m, HasCallStack) | |
=> (e -> Maybe b) | |
-> m a | Action to run |
-> m (Either b a) |
withException :: forall e a m b. (Exception e, MonadCatch m, HasCallStack) => m a -> (e -> m b) -> m a Source #
checkpoint :: (HasCallStack, MonadCatch m) => Annotation -> m a -> m a #
Add a single Annotation
to any exceptions thrown in the following
action. The CallStack
present on any AnnotatedException
will also be
updated to include this location.
Example:
main = do checkpoint "Foo" $ do print =<< readFile "I don't exist.markdown"
The exception thrown due to a missing file will now have an Annotation
Foo
.
Since: annotated-exception-0.1.0.0
checkpointMany :: (MonadCatch m, HasCallStack) => [Annotation] -> m a -> m a #
Add the list of Annotation
to any exception thrown in the following
action.
Since: annotated-exception-0.1.0.0
:: forall m a. (MonadCatch m, HasCallStack) | |
=> m a | Action that might throw whatever types of exceptions |
-> m a | Action that only throws |
When dealing with a library that does not use AnnotatedException
,
apply this function to augment its exceptions with call stacks.
Miscellany
class Monad m => MonadThrow (m :: Type -> Type) #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Instances
class MonadThrow m => MonadCatch (m :: Type -> Type) #
A class for monads which allow exceptions to be caught, in particular
exceptions which were thrown by throwM
.
Instances should obey the following law:
catch (throwM e) f = f e
Note that the ability to catch an exception does not guarantee that we can
deal with all possible exit points from a computation. Some monads, such as
continuation-based stacks, allow for more than just a success/failure
strategy, and therefore catch
cannot be used by those monads to properly
implement a function such as finally
. For more information, see
MonadMask
.
Instances
class MonadCatch m => MonadMask (m :: Type -> Type) #
A class for monads which provide for the ability to account for all possible exit points from a computation, and to mask asynchronous exceptions. Continuation-based monads are invalid instances of this class.
Instances should ensure that, in the following code:
fg = f `finally` g
The action g
is called regardless of what occurs within f
, including
async exceptions. Some monads allow f
to abort the computation via other
effects than throwing an exception. For simplicity, we will consider aborting
and throwing an exception to be two forms of "throwing an error".
If f
and g
both throw an error, the error thrown by fg
depends on which
errors we're talking about. In a monad transformer stack, the deeper layers
override the effects of the inner layers; for example, ExceptT e1 (Except
e2) a
represents a value of type Either e2 (Either e1 a)
, so throwing both
an e1
and an e2
will result in Left e2
. If f
and g
both throw an
error from the same layer, instances should ensure that the error from g
wins.
Effects other than throwing an error are also overridden by the deeper layers.
For example, StateT s Maybe a
represents a value of type s -> Maybe (a,
s)
, so if an error thrown from f
causes this function to return Nothing
,
any changes to the state which f
also performed will be erased. As a
result, g
will see the state as it was before f
. Once g
completes,
f
's error will be rethrown, so g
' state changes will be erased as well.
This is the normal interaction between effects in a monad transformer stack.
By contrast, lifted-base's
version of finally
always discards all of g
's non-IO effects, and g
never sees any of f
's non-IO effects, regardless of the layer ordering and
regardless of whether f
throws an error. This is not the result of
interacting effects, but a consequence of MonadBaseControl
's approach.
Instances
MonadMask IO | |
e ~ SomeException => MonadMask (Either e) | Since: exceptions-0.8.3 |
Defined in Control.Monad.Catch | |
MonadMask (AppExample app) Source # | |
Defined in Freckle.App.Test mask :: ((forall a. AppExample app a -> AppExample app a) -> AppExample app b) -> AppExample app b # uninterruptibleMask :: ((forall a. AppExample app a -> AppExample app a) -> AppExample app b) -> AppExample app b # generalBracket :: AppExample app a -> (a -> ExitCase b -> AppExample app c) -> (a -> AppExample app b) -> AppExample app (b, c) # | |
MonadMask m => MonadMask (LoggingT m) | |
Defined in Control.Monad.Logger | |
MonadMask m => MonadMask (NoLoggingT m) | |
Defined in Control.Monad.Logger mask :: ((forall a. NoLoggingT m a -> NoLoggingT m a) -> NoLoggingT m b) -> NoLoggingT m b # uninterruptibleMask :: ((forall a. NoLoggingT m a -> NoLoggingT m a) -> NoLoggingT m b) -> NoLoggingT m b # generalBracket :: NoLoggingT m a -> (a -> ExitCase b -> NoLoggingT m c) -> (a -> NoLoggingT m b) -> NoLoggingT m (b, c) # | |
MonadMask m => MonadMask (WriterLoggingT m) | |
Defined in Control.Monad.Logger mask :: ((forall a. WriterLoggingT m a -> WriterLoggingT m a) -> WriterLoggingT m b) -> WriterLoggingT m b # uninterruptibleMask :: ((forall a. WriterLoggingT m a -> WriterLoggingT m a) -> WriterLoggingT m b) -> WriterLoggingT m b # generalBracket :: WriterLoggingT m a -> (a -> ExitCase b -> WriterLoggingT m c) -> (a -> WriterLoggingT m b) -> WriterLoggingT m (b, c) # | |
MonadMask m => MonadMask (ResourceT m) | |
Defined in Control.Monad.Trans.Resource.Internal mask :: ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b # uninterruptibleMask :: ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b # generalBracket :: ResourceT m a -> (a -> ExitCase b -> ResourceT m c) -> (a -> ResourceT m b) -> ResourceT m (b, c) # | |
MonadMask m => MonadMask (MaybeT m) | Since: exceptions-0.10.0 |
Defined in Control.Monad.Catch | |
MonadMask m => MonadMask (AppT app m) Source # | |
Defined in Freckle.App | |
MonadMask m => MonadMask (ValidateT e m) | |
Defined in Control.Monad.Validate.Internal mask :: ((forall a. ValidateT e m a -> ValidateT e m a) -> ValidateT e m b) -> ValidateT e m b # uninterruptibleMask :: ((forall a. ValidateT e m a -> ValidateT e m a) -> ValidateT e m b) -> ValidateT e m b # generalBracket :: ValidateT e m a -> (a -> ExitCase b -> ValidateT e m c) -> (a -> ValidateT e m b) -> ValidateT e m (b, c) # | |
(Error e, MonadMask m) => MonadMask (ErrorT e m) | |
Defined in Control.Monad.Catch | |
MonadMask m => MonadMask (ExceptT e m) | Since: exceptions-0.9.0 |
Defined in Control.Monad.Catch mask :: ((forall a. ExceptT e m a -> ExceptT e m a) -> ExceptT e m b) -> ExceptT e m b # uninterruptibleMask :: ((forall a. ExceptT e m a -> ExceptT e m a) -> ExceptT e m b) -> ExceptT e m b # generalBracket :: ExceptT e m a -> (a -> ExitCase b -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m (b, c) # | |
MonadMask m => MonadMask (IdentityT m) | |
Defined in Control.Monad.Catch mask :: ((forall a. IdentityT m a -> IdentityT m a) -> IdentityT m b) -> IdentityT m b # uninterruptibleMask :: ((forall a. IdentityT m a -> IdentityT m a) -> IdentityT m b) -> IdentityT m b # generalBracket :: IdentityT m a -> (a -> ExitCase b -> IdentityT m c) -> (a -> IdentityT m b) -> IdentityT m (b, c) # | |
MonadMask m => MonadMask (ReaderT r m) | |
Defined in Control.Monad.Catch mask :: ((forall a. ReaderT r m a -> ReaderT r m a) -> ReaderT r m b) -> ReaderT r m b # uninterruptibleMask :: ((forall a. ReaderT r m a -> ReaderT r m a) -> ReaderT r m b) -> ReaderT r m b # generalBracket :: ReaderT r m a -> (a -> ExitCase b -> ReaderT r m c) -> (a -> ReaderT r m b) -> ReaderT r m (b, c) # | |
MonadMask m => MonadMask (StateT s m) | |
Defined in Control.Monad.Catch | |
MonadMask m => MonadMask (StateT s m) | |
Defined in Control.Monad.Catch | |
(MonadMask m, Monoid w) => MonadMask (WriterT w m) | |
Defined in Control.Monad.Catch mask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # uninterruptibleMask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # generalBracket :: WriterT w m a -> (a -> ExitCase b -> WriterT w m c) -> (a -> WriterT w m b) -> WriterT w m (b, c) # | |
(MonadMask m, Monoid w) => MonadMask (WriterT w m) | |
Defined in Control.Monad.Catch mask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # uninterruptibleMask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # generalBracket :: WriterT w m a -> (a -> ExitCase b -> WriterT w m c) -> (a -> WriterT w m b) -> WriterT w m (b, c) # | |
(MonadMask m, Monoid w) => MonadMask (RWST r w s m) | |
Defined in Control.Monad.Catch mask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # uninterruptibleMask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # generalBracket :: RWST r w s m a -> (a -> ExitCase b -> RWST r w s m c) -> (a -> RWST r w s m b) -> RWST r w s m (b, c) # | |
(MonadMask m, Monoid w) => MonadMask (RWST r w s m) | |
Defined in Control.Monad.Catch mask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # uninterruptibleMask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # generalBracket :: RWST r w s m a -> (a -> ExitCase b -> RWST r w s m c) -> (a -> RWST r w s m b) -> RWST r w s m (b, c) # |
module Freckle.App.Exception.Types