Liking cljdoc? Tell your friends :D

cats.monad.exception

The Exception monad.

Also known as Try monad, popularized by Scala.

It represents a computation that may either result in an exception or return a successfully computed value. Is very similar to Either monad, but is semantically different.

It consists in two types: Success and Failure. The Success type is a simple wrapper like Right of Either monad. But the Failure type is slightly different from Left, because it is forced to wrap an instance of Throwable (or Error in cljs).

The most common use case of this monad is for wrap third party libraries that uses standard Exception based error handling. In normal circumstances you should use Either instead.

The types defined for Exception monad (Success and Failure) also implementes the clojure IDeref interface which facilitates libraries developing using monadic composition without forcing a user of that library to use or understand monads.

That is because when you will dereference the failure instance, it will reraise the containing exception.

The Exception monad.

Also known as Try monad, popularized by Scala.

It represents a computation that may either result
in an exception or return a successfully computed
value. Is very similar to Either monad, but is
semantically different.

It consists in two types: Success and Failure. The
Success type is a simple wrapper like Right of Either
monad. But the Failure type is slightly different
from Left, because it is forced to wrap an instance
of Throwable (or Error in cljs).

The most common use case of this monad is for wrap
third party libraries that uses standard Exception
based error handling. In normal circumstances you
should use Either instead.

The types defined for Exception monad (Success and
Failure) also implementes the clojure IDeref interface
which facilitates libraries developing using monadic
composition without forcing a user of that library
to use or understand monads.

That is because when you will dereference the
failure instance, it will reraise the containing
exception.
raw docstring

exception?clj/s

(exception? v)

Return true in case of v is instance of Exception monad.

Return true in case of `v` is instance
of Exception monad.
sourceraw docstring

extractclj/s

(extract mv)
(extract mv default)

Return inner value from exception monad.

This is a specialized version of cats.core/extract for Exception monad types that allows set up the default value.

If a provided mv is an instance of Failure type it will re raise the inner exception. If you need extract value without raising it, use cats.core/extract function for it.

Return inner value from exception monad.

This is a specialized version of `cats.core/extract`
for Exception monad types that allows set up
the default value.

If a provided `mv` is an instance of Failure type
it will re raise the inner exception. If you need
extract value without raising it, use `cats.core/extract`
function for it.
sourceraw docstring

failureclj/s

(failure e)
(failure e message)

A failure type constructor.

If a provided parameter is an exception, it wraps it in a Failure instance and return it. But if a provided parameter is arbitrary data, it tries create an exception from it using clojure ex-info function.

Take care that ex-info function in clojurescript differs a little bit from clojure.

A failure type constructor.

If a provided parameter is an exception, it wraps
it in a `Failure` instance and return it. But if
a provided parameter is arbitrary data, it tries
create an exception from it using clojure `ex-info`
function.

Take care that `ex-info` function in clojurescript
differs a little bit from clojure.
sourceraw docstring

Failurecljs

source

failure?clj/s

(failure? v)

Return true if v is an instance of the Failure type.

Return true if `v` is an instance of
the Failure type.
sourceraw docstring

successclj/s

(success v)

A Success type constructor.

It wraps any arbitrary value into success type.

A Success type constructor.

It wraps any arbitrary value into
success type.
sourceraw docstring

Successcljs

source

success?clj/s

(success? v)

Return true if v is an instance of the Success type.

Return true if `v` is an instance of
the Success type.
sourceraw docstring

throw-exceptionclj/s

(throw-exception message)
source

throwable?clj/s

(throwable? e)

Return true if v is an instance of the Throwable or js/Error type.

Return true if `v` is an instance of
the Throwable or js/Error type.
sourceraw docstring

try-onclj/smacro

(try-on expr)

Wraps a computation and return success of failure.

Wraps a computation and return success of failure.
sourceraw docstring

try-or-elseclj/smacro

(try-or-else expr defaultvalue)
source

try-or-recoverclj/smacro

(try-or-recover expr func)
source

wrapclj/s

(wrap func)

Wrap a function in a try monad.

Is a high order function that accept a function as parameter and returns an other that returns success or failure depending of result of the first function.

Wrap a function in a try monad.

Is a high order function that accept a function
as parameter and returns an other that returns
success or failure depending of result of the
first function.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close