HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecardano-api-11.7.0.0

Cardano.Api.Monad.Error

  • 4 types
  • 3 classes
  • 49 values
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.

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

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

valuebracketExceptionT
  1. :: MonadMask m
  2. => ExceptT e m a
  3. -> a -> ExceptT e m c
  4. -> a -> ExceptT e m b
  5. -> ExceptT e m b
#

Acquire a resource in ExceptT and then perform an action with it, cleaning up afterwards regardless of left or exception.

Like bracketExceptT, but the cleanup is called even when the bracketed function throws an exception. Exceptions in the bracketed function are caught to allow the cleanup to run and then rethrown.

valueexceptT :: Monad m => (x -> m b) -> (a -> m b) -> ExceptT x m a -> m b
#

Map over both arguments at the same time.

Specialised version of bimap for ExceptT.

valuehandleExceptT
  1. :: (MonadCatch m, Exception e)
  2. => e -> x
  3. -> m a
  4. -> ExceptT x m a
#

Try any monad action and catch the specified exception, wrapping it to convert it to the error type of the ExceptT transformer. Exceptions other that the specified exception type will escape the ExceptT transformer.

  • Warning*: This function should be used with caution! In particular, it is bad practice to catch SomeException because that includes asynchronous exceptions like stack/heap overflow, thread killed and user interrupt. Trying to handle StackOverflow, HeapOverflow and ThreadKilled exceptions could cause your program to crash or behave in unexpected ways.

valuehandlesExceptT
  1. :: (Foldable f, MonadCatch m)
  2. => f (Handler m x)
  3. -> m a
  4. -> ExceptT x m a
#

Try a monad action and catch any of the exceptions caught by the provided handlers. The handler for each exception type needs to wrap it to convert it to the error type of the ExceptT transformer. Exceptions not explicitly handled by the provided handlers will escape the ExceptT transformer.

valuehushM :: Monad m => Either e a -> (e -> m ()) -> m (Maybe a)
#

Convert an Either to a Maybe and execute the supplied handler in the Left case.

classclass Monad m => MonadIO (m :: Type -> Type) where
#

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Methods

  • liftIO :: IO a -> m a

    Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).

    Example
    import Control.Monad.Trans.State -- from the "transformers" library
    
    printState :: Show s => StateT s IO ()
    printState = do
      state <- get
      liftIO $ print state

    Had we omitted liftIO, we would have ended up with this error:

    • Couldn't match type ‘IO’ with ‘StateT s IO’
     Expected type: StateT s IO ()
       Actual type: IO ()

    The important part here is the mismatch between StateT s IO () and IO ().

    Luckily, we know of a function that takes an IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

    > evalStateT printState "hello"
    "hello"
    
    > evalStateT printState 3
    3
    
Instances71Lifting, MonadIO, …
classclass Monad m => MonadError e (m :: Type -> Type) | m -> e where
#

The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.

Is parameterized over the type of error information and the monad type constructor. It is common to use Either String as the monad type constructor for an error monad in which error descriptions take the form of strings. In that case and many other common cases the resulting monad is already defined as an instance of the MonadError class. You can also define your own error type and/or use a monad type constructor other than Either String or Either IOError. In these cases you will have to explicitly define instances of the MonadError class. (If you are using the deprecated Control.Monad.Error or Control.Monad.Trans.Error, you may also have to define an Error instance.)

Methods

  • throwError :: e -> m a

    Is used within a monadic computation to begin exception processing.

  • catchError :: m a -> (e -> m a) -> m a

    A handler function to handle previous errors and return to normal execution. A common idiom is:

    do { action1; action2; action3 } `catchError` handler

    where the action functions can call throwError. Note that handler and the do-block must have the same return type.

Instances55Lifting, MonadError, …
classclass (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) where
#

The class of monad transformers. For any monad m, the result t m should also be a monad, and lift should be a monad transformation from m to t m, i.e. it should satisfy the following laws:

Since 0.6.0.0 and for GHC 8.6 and later, the requirement that t m be a Monad is enforced by the implication constraint forall m. Monad m => Monad (t m) enabled by the QuantifiedConstraints extension.

Ambiguity error with GHC 9.0 to 9.2.2

These versions of GHC have a bug (https://gitlab.haskell.org/ghc/ghc/-/issues/20582) which causes constraints like

(MonadTrans t, forall m. Monad m => Monad (t m)) => ...

to be reported as ambiguous. For transformers 0.6 and later, this can be fixed by removing the second constraint, which is implied by the first.

Methods

  • lift :: Monad m => m a -> t m a

    Lift a computation from the argument monad to the constructed monad.

Instances66MonadTrans, …
typetype Except e = ExceptT e Identity
#

The parameterizable exception monad.

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.

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

A monad transformer that adds exceptions to other monads.

ExceptT constructs a 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

Instances90MonadRWS, FunctorT, TraversableT, DistributiveT, MFunctor, Generic1, …