NetRexx follows the block-oriented exception handling model of Java and C++. Instead of introducing a new construct, however (which can introduce extra levels of nesting in a program), it extends the DO, LOOP, and SELECT constructs to allow any block to include exception handlers.
Specifically, where an END clause can appear in these constructs, zero or more CATCH instructions can be used to define exception handlers, followed by zero or one FINALLY instructions that describe 'clean-up' code for the block. The whole construct continues to be ended by an END clause. For example:
if a=b then do /* could be LOOP i=1 to 10, etc. */ j=oddone(i, j) say something(7)/j catch ZeroDivide say 'oddone('i','j') returned zero' catch ex=Exception /* catches everything else, probably */ /* 'ex' is assigned the exception object */ say 'Exception:' ex.getMessage finally say 'Done!' end
FINALLY, like OTHERWISE in SELECT, implies a semicolon after it, so the last SAY in the example could have appeared on the same line as the FINALLY without an intervening semicolon.
The SIGNAL instruction is used to raise (throw) an exception.
[ previous section | contents | next section ]
From 'netrexx.doc', version 0.75.
Copyright(c) IBM Corporation, 1996. All rights reserved. ©