MonadError is the typeclass used to explicitly represent errors during sequential execution. It is parametrized to an error type E, which means the datatype has at least a “success” and a “failure” version. These errors can come in the form of Throwable, Exception, or any other type hierarchy of the user’s choice.

MonadError extends from ApplicativeError, which is already used to represent errors in independent computations. This way, all the methods ApplicativeError provides to handle recovery from errors are also available in MonadError.

Main Combinators

MonadError inherits all the combinators available in ApplicativeError and Monad. It also adds one of its own.


Inherited from ApplicativeError. A constructor function. It lifts an exception into the computational context of a type constructor.

import arrow.*
import arrow.core.*
import arrow.core.extensions.either.applicativeError.*

val eitherResult: Either<Throwable, Int> =

// Left(java.lang.RuntimeException: BOOM!)
import arrow.fx.*

val ioResult: IO<Int> =

// Left(java.lang.RuntimeException: BOOM!)

Kind<F, A>.ensure

Tests a predicate against the object, and, if it fails, it executes a function to create an error.

import arrow.core.extensions.either.monadError.*

Either.Right(1).ensure({ RuntimeException("Failed predicate") }, { it > 0 })
// Right(1)
Either.Right(1).ensure({ RuntimeException("Failed predicate") }, { it < 0 })
// Left(java.lang.RuntimeException: Failed predicate)



It starts a Monad Comprehension that wraps any exception thrown in the block inside raiseError().


Arrow provides MonadErrorLaws in the form of test cases for internal verification of lawful instances and third party apps creating their own MonadError instances.

Data types

Module Data types
arrow.core Either, Option, Try
arrow.fx IO
arrow.mtl AccumT, EitherT, Kleisli, OptionT, StateT, WriterT

Type Class Hierarchy

Do you like Arrow?

Arrow Org