NetRexx Overview, version 1.148
Copyright (c) IBM Corporation, 1998. All rights reserved. ©
23 Dec 1998
[previous | contents | next]

Exception and error handling

NetRexx 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.'
  end
Here, 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, mfc@uk.ibm.com (ISBN 0-13-806332-X, 197pp, Prentice-Hall, 1997).