HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Moduletransformers-0.6.3.0Haskell2010

Control.Monad.Trans.Except

This monad transformer extends a monad with the ability to throw and catch exceptions.

A sequence of actions terminates normally, producing a value, only if none of the actions in the sequence throws an exception. If one throws an exception, the rest of the sequence is skipped and the composite action exits with that exception.

If the value of the exception is not required, the variant in Control.Monad.Trans.Maybe may be used instead.

  • 2 types
  • 15 values

The Except monad

5 declarations
typetype Except e = ExceptT e Identity
#

The parameterizable exception monad, which is strict.

Computations are either exceptions (of any type) or normal values. These computations are plain values, and are unrelated to the Control.Exception mechanism, which is tied to the IO monad.

The return function returns a normal value, while >>= exits on the first exception. For a variant that continues after an error and collects all the errors, see Errors.

valuewithExcept :: (e -> e') -> Except e a -> Except e' a
#

Transform any exceptions thrown by the computation using the given function (a specialization of withExceptT).

The ExceptT monad transformer

3 declarations
newtypenewtype ExceptT e (m :: Type -> Type) a
#

A monad transformer that adds exceptions to other monads.

ExceptT constructs a strict monad parameterized over two things:

  • e - An arbitrary exception type.

  • m - The inner monad.

The monadic computations are a plain values. They are unrelated to the Control.Exception mechanism, which is tied to the IO monad.

The return function yields a computation that produces the given value, while >>= sequences two subcomputations, exiting on the first exception.

Constructors

Instances25Generic1, MonadTrans, Monad, Functor, MonadFix, MonadFail, …

Exception operations

6 declarations
valuefinallyE :: Monad m => ExceptT e m a -> ExceptT e m () -> ExceptT e m a
#

finallyE a b executes computation a followed by computation b, even if a exits early by throwing an exception. In the latter case, the exception is re-thrown after b has been executed.

valueonE :: Monad m => ExceptT e m a -> ExceptT e m b -> ExceptT e m a
#

If the first action succeeds, return its value, ignoring the second action. If the first action throws an exception, run the second action and then throw an exception, either the one thrown by the second action, if any, or the one thrown by the first action.

Lifting other operations

3 declarations