Error handling, exceptions.

Primary

catch

Available since version 1.0 (view source)

not referred automatically

MACRO (catch ex-type ex & body)

A catch clause.

See also: try, finally, throw

cause

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (cause ex)

Type signature:
  • (IException) → (Maybe IException)

Returns cause for given exception, or nil if exception does not contain a cause.

See also: message, root-cause

error

Available since version 1.0 (view source)

Usage:
  • (error x)

Type signature:
  • (IFailAware) → (Maybe IException)

Returns first exception which has caused object x to fail. Returns nil if object is not in a failed state.

See also: fail-aware?, fail!

error-handleable?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (error-handleable? x)

Type signature: Predicate

Returns true if object x satisfies IErrorHandleable protocol, false otherwise.

error-handler

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (error-handler x)

Type signature:
  • (IErrorHandleable) → IReference

Returns reference to the error handler fn for x.

error-mode

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (error-mode x)

Type signature:
  • (IErrorHandleable) → IReference

Returns reference to the error mode for x.

exception?

Available since version 1.0 (view source)

Usage:
  • (exception? x)

Type signature: Predicate

Returns true if object x satisfies IException protocol, false otherwise.

See also: IException, throw, try, catch

fail!

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (fail! x exception)

  • (fail! x exception throw?)

Type signatures:
  • (IFailable ⨯ IException) → nil

  • (IFailable ⨯ IException ⨯ Boolean+) → nil

Reports a failed state to the failable object. Returns nil. Throws if throw? is true.

See also: error, fragile

fail-aware?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (fail-aware? x)

Type signature: Predicate

Returns true if object x satisfies IFailAware protocol, false otherwise.

See also: IFailAware, error

finally

Available since version 1.0 (view source)

not referred automatically

MACRO (finally & body)

A finally clause.

See also: try, catch, throw

fragile

Available since version 1.0 (view source)

not referred automatically

MACRO (fragile x & body)

Wraps body in a try-catch which makes x failed if exception occurs.

See also: opened-fragile, fail!

message

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (message ex)

Type signature:
  • (IException) → (Maybe String+)

Returns message for given exception, or nil if exception does not contain a message.

See also: ex-data, cause

opened-fragile

Available since version 1.0 (view source)

not referred automatically

MACRO (opened-fragile x & body)

Like fragile, but ensures stateful object x is also opened.

root-cause

Available since version 1.0 (alias of clojure.stacktrace/root-cause)

not referred automatically

Usage:
  • (root-cause tr)

Type signature:
  • (IException) → (Maybe IException)

Returns the last 'cause' Throwable in a chain of Throwables.

See also: cause, stack-trace

stack-trace

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (stack-trace ex)

Type signature:
  • (IException) → [KeywordMap]

Returns collection of frame maps representing given stack trace.

suppressed

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (suppressed ex)

Type signature:
  • (IException) → []

Returns collection of suppressed exceptions.

throw

Available since version 1.0 (view source)

MACRO (throw expr)

The expr is evaluated and thrown, therefore it should yield an instance of IException.

See also: try, catch, finally

try

Available since version 1.0 (view source)

MACRO (try & exprs)

The exprs are evaluated and, if no exceptions occur, the value of the last is returned. If an exception occurs and catch clauses are provided, each is examined in turn and the first for which the thrown exception is an instance of the named class is considered a matching catch clause. If there is a matching catch clause, its exprs are evaluated in a context in which name is bound to the thrown exception, and the value of the last is the return value of the function. If there is no matching catch clause, the exception propagates out of the function. Before returning, normally or abnormally, any finally exprs will be evaluated for their side effects.

See also: catch, finally, throw

Exceptions

ex-data

Available since version 1.0 (alias of clojure.core/ex-data)

Usage:
  • (ex-data ex)

Type signature:
  • ((Maybe IException)) → {}

Returns exception data (a map) if ex is an IExceptionInfo. Otherwise returns nil.

See also: ex-info

ex-info

Available since version 1.0 (view source)

MACRO (ex-info msg)  (ex-info msg map)  (ex-info msg map cause)

Create an instance of ExceptionInfo, a RuntimeException subclass that carries a map of additional data.

See also: ex-data

illegal-argument

Available since version 1.0 (view source)

MACRO (illegal-argument)  (illegal-argument msg)  (illegal-argument msg cause)

Returns illegal argument exception optionally with given msg string and cause exception.

See also: throw

illegal-state

Available since version 1.0 (view source)

MACRO (illegal-state)  (illegal-state msg)  (illegal-state msg cause)

Returns illegal state exception optionally with given msg string and cause exception.

See also: throw

index-out-of-bounds

Available since version 1.0 (view source)

MACRO (index-out-of-bounds)  (index-out-of-bounds msg)

Returns index out of bounds exception optionally with given msg string.

See also: throw

io

Available since version 1.0 (view source)

MACRO (io)  (io msg)  (io msg cause)

Returns IO exception optionally with given msg string and cause exception.

See also: throw

no-such-element

Available since version 1.0 (view source)

MACRO (no-such-element)  (no-such-element msg)

Returns no such element exception optionally with given msg string.

See also: throw

npe

Available since version 1.0 (view source)

MACRO (npe)  (npe msg)

Returns null pointer exception optionally with given msg string.

See also: throw

unsupported-operation

Available since version 1.0 (view source)

MACRO (unsupported-operation)  (unsupported-operation msg)

Returns unsupported operation exception optionally with given msg string.

See also: throw