NetRexx Overview, version 2.02
Copyright (c) IBM Corporation, 2001. All rights reserved. ©
22 May 2001
[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:'



    say 'The reciprocal of' number 'is:' 1/number

  catch Exception

    say 'Sorry, could not divide "'number'" into 1'

    say 'Please try again.'


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, (ISBN 0-13-806332-X, 197pp, Prentice-Hall, 1997).