The Exception proto is used for raising exceptions and instances are used to hold rexception 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
|