Library exceptions

This is exported from the core library, which means you don't need to import it.

Exception throwing and handling.

Globals

Assertion failed error.
Thrown when an assertion fails both by the 'assert:' language construct and by other assertion checking libraries.

Cancelled error.
Thrown when a task has been cancelled.

Deadline exceeded error.
Thrown when a with-timeout times out.

Functions

catch --trace/bool=false --unwind/bool=false [block] -> any
If an exception is thrown during the block call, then the trace is printed if the trace is true (and the trace can otherwise be printed).
If an exception is thrown during the block call, then unwinding continues if the unwind is true.

catch --trace/bool=false [--unwind] [block] -> any
If an exception is thrown during the block call, then the trace is printed if the trace is true (and the trace can otherwise be printed).

catch [--trace] --unwind/bool=false [block] -> any
If an exception is thrown during the block call, then unwinding continues if the unwind is true.

catch [--trace] [--unwind] [block] -> any
Catches exceptions thrown in the given block.
Returns null if the call to the block completes without exception.
Returns the thrown exception if an exception is thrown during the call of the block and unwind returns a falsy value (see below).
The trace block decides whether the trace should be printed in case an exception has been thrown. The trace block is called with the thrown exception and the trace (trace.call exception trace) and should return a boolean. If the trace call returns true, then the trace is printed. However, the trace can only be printed if there is a trace and this task hasn't been cancelled.
The unwind block decides whether unwinding should continue in case of a caught exception. The unwind block is called with the thrown exception and the trace (unwind.call exception trace) and should return a boolean value. If unwind call returns true, then unwinding continues.

rethrow exception/any trace/ByteArray -> none
Rethrows the given exception along with the trace.
Works like throw except it uses the given trace rather than generating one at the throw point.
Used to rethrow a caught exception (see catch [--trace] [block]) as though it wasn't caught.

throw exception/any -> none
Throws the given exception.
Unwinds the stack of this task calling associated finally-blocks. By default, a task with an exception will print the stack trace and terminate the task.
The exception can also be caught with a catch [block].

unreachable -> none
Marks code point as unreachable.
Must not be reached in the program.