Transforms exceptions with a function, doing nothing on successful results.
Examples:
(pure 2 : Except String Nat).mapError (·.length) = pure 2
(throw "Error" : Except String Nat).mapError (·.length) = throw 5
Equations
Instances For
Sequences two operations that may throw exceptions, allowing the second to depend on the value returned by the first.
If the first operation throws an exception, then it is the result of the computation. If the first succeeds but the second throws an exception, then that exception is the result. If both succeed, then the result is the result of the second computation.
This is the implementation of the >>=
operator for Except ε
.
Equations
Instances For
Handles exceptions thrown in the Except ε
monad.
If ma
is successful, its result is returned. If it throws an exception, then handle
is invoked
on the exception's value.
Examples:
(pure 2 : Except String Nat).tryCatch (pure ·.length) = pure 2
(throw "Error" : Except String Nat).tryCatch (pure ·.length) = pure 5
(throw "Error" : Except String Nat).tryCatch (fun x => throw ("E: " ++ x)) = throw "E: Error"
Equations
Instances For
Recovers from exceptions thrown in the Except ε
monad. Typically used via the <|>
operator.
Except.tryCatch
is a related operator that allows the recovery procedure to depend on which
exception was thrown.
Equations
Instances For
Use a monadic action that may return an exception's value as an action in the transformed monad that may throw the corresponding exception.
This is the inverse of ExceptT.run
.
Equations
Instances For
Use a monadic action that may throw an exception as an action that may return an exception's value.
This is the inverse of ExceptT.mk
.
Equations
Instances For
Equations
Equations
Equations
An alternative unconditional error recovery operator that allows callers to specify which exception to throw in cases where both operations throw exceptions.
By default, the first is thrown, because the <|>
operator throws the second.
Equations
Instances For
Equations
Instances For
Equations
Monads that provide the ability to ensure an action happens, regardless of exceptions or other failures.
MonadFinally.tryFinally'
is used to desugar try ... finally ...
syntax.
Runs an action, ensuring that some other action always happens afterward.
More specifically,
tryFinally' x f
runsx
and then the “finally” computationf
. Ifx
succeeds with some valuea : α
,f (some a)
is returned. Ifx
fails form
's definition of failure,f none
is returned.tryFinally'
can be thought of as performing the same role as afinally
block in an imperative programming language.
Instances
Execute x
and then execute finalizer
even if x
threw an exception