 Signal instruction signal term; The signal instruction causes an 'abnormal' change in the flow of control, by raising an exception. The exception term may be a term that constructs or evaluates to an exception object, or it may be expressed as the name of an exception type (in which case the default constructor, with no arguments, for that type is used to construct an exception object). The exception object then represents the exception and is available, if required, when the exception is handled. The handling of exceptions is detailed in the Exceptions section. In summary, when an exception is signalled, all active pending do groups, loop loops, if constructs, and select constructs may be ended. For each one in turn, from the innermost: - No further clauses within the body of the construct will be executed (in this respect, signal acts like a leave for the construct).
- The instructionlist following the first catch clause that matches the exception, if any, is executed.
- The instructionlist following the finally clause for the construct, if any, is executed.
If a catch matched the exception the exception is deemed handled, and execution resumes as though the construct ended normally (unless a new exception was signalled in the catch or finally instruction lists, in which case it is processed). Otherwise, any enclosing construct is ended in the same manner. If there is no enclosing construct, then the current method is ended and the exception is signalled in the caller. Examples: signal RxErrorTrace signal DivideException('Divide by zero') In the reference implementation, the term must either - evaluate to an object that is assignable to the type Throwable (for example, a subclass of Exception or RuntimeException).
- be a type that is a subclass of Throwable, in which case the default constructor (with no arguments) for the given type is used to construct the exception object.
|