|
Exception and error handlingNetRexx doesn't have a goto instruction, but a signal instruction is provided for abnormal transfer of control, such as when something unusual occurs. Using signal raises an exception; all control instructions are then unwound until the exception is caught by a control instruction that specifies a suitable catch instruction for handling the exception.Exceptions are also raised when various errors occur, such as attempting to divide a number by zero. For example: say 'Please enter a number:' number=ask do say 'The reciprocal of' number 'is:' 1/number catch Exception say 'Sorry, could not divide "'number'" into 1' say 'Please try again.' endHere, the catch instruction will catch any exception that is raised when the division is attempted (conversion error, divide by zero, etc.), and any instructions that follow it are then executed. If no exception is raised, the catch instruction (and any instructions that follow it) are ignored. Any of the control instructions that end with end (do, loop, or select) may be modified with one or more catch instructions to handle exceptions. [previous | contents | next] From
The NetRexx Language by
Mike Cowlishaw,
|