The Exception proto is used for raising exceptions; instances hold exception-related info.
Raise
An exception can be raised by calling raise() on an exception proto. Exception raise("generic foo exception")
Try and Catch
To catch an exception, the try() method of the Object proto is used. try() will catch any exceptions that occur within it and return the caught exception or nil if no exception is caught.
e := try(To catch a particular exception, the Exception catch() method can be used. Example:)
e := try(
// ...
)
e catch(Exception,
writeln(e coroutine backtraceString)
)
The first argument to catch indicates which types of exceptions will be caught. catch() returns the exception if it doesn't match and nil if it does.
Pass
To re-raise an exception caught by try(), use the pass method. This is useful to pass the exception up to the next outer exception handler, usually after all catches failed to match the type of the current exception:
e := try(
// ...
)
e catch(Error,
// ...
) catch(Exception,
// ...
) pass
Custom Exceptions
Custom exception types can be implemented by simply cloning an existing Exception type:
MyErrorType := Error clone
A simple object whose invoke(v) returns v.
Walks handler stacks from the current coroutine up through the parentCoroutine chain. Returns the first matching handler block for this exception type, or nil.
Catch an exception with the specified exception prototype.
Returns the message object associated with the exception.
Returns the coroutine that the exception occurred in.
Returns the nestedException if there is one.
Returns the call object associated with the exception.
Pass the exception up the stack.
Raise an exception with the specified error message.
Print the exception and related stack.
Raises a resumable exception. If a matching handler is installed via withHandler, the handler is called with (exception, resume). The handler can resume execution at the signal site by calling resume invoke(value), or simply returning a value (which auto-resumes). If no handler is found, falls back to non-resumable raise.