Exception and error handling


NetRexx doesn't have a GOTO statement, but a SIGNAL statement is provided for abnormal transfer of control, such as when something unusual occurs. Using SIGNAL raises an exception; all control statements are then 'unwound' until the exception is caught by a control statement that specifies a suitable CATCH statement 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'
  end

Here, the CATCH statement will catch any exception that is raised when the division is attempted (conversion error, divide by zero, etc.).

Any control statement that ends with END (DO, LOOP, or SELECT) may be modified with one or more CATCH statements to handle exceptions.


[ previous section | contents | next section ]

From 'nrover.doc', version 1.113.
Copyright(c) IBM Corporation, 1996, 1997. All rights reserved. ©