| Directives |
|
| Structured
error handling is a +PxPlus
Exclusive |
|||||
| Format | ....
ON ERR [ { ] directives
[ } ] Where: |
||||
| directives | Directives to execute in case an error occurs during the execution of the directives preceeding the ON ERR. The curly brackets are only needed if you want additional directives following the ON ERR to be executed. | ||||
| Description | The
directives GOSUB, WHILE, FOR, REPEAT and SELECT support
an enhanced ON ERR option that allows you to specify what
logic is to be executed should an error occur within
their respective logic block. Example:
Including an ON ERR clause following the label/statement number in a GOSUB tells the system that should an un-trapped error occur when processing the GOSUB logic, the system is to execute the remainder of the line following ON ERR. By default, the complete line following the ON ERR will be processed however you may also include curly brackets to define the logic to be executed as in:
In this case if an error occur during the WHILE loop (in this example an end of file) the system will transfer control to the BREAK directive. |
||||
| *Note* | In
the above example, the system actually transfers control
to the ON ERR clause but does not actually exit the WHILE
loop. Should the ON ERR logic not exit the loop or cause
the loop to terminate the loop will continue to execute.
For Example:
This code will generate a divide error when N equals zero at which point the ON ERR logic will be executed. |
||||
The
ON ERR clause is automatically cascaded to lower levels
thus an un-trapped error at a lower level will cause the
system to exit the lower levels and return control to the
upper level to handle the error. For example. if we
modify the prior example:
CHECK_N:
The actual divide error will occur in the lower level GOSUB however the existence of the ON ERR clause will result in the system automatically exiting the GOSUB and returning control to the outer WHILE loop. For all but the GOSUB, the ON ERR logic will be executed while functionally still within the loop structure. The system just executes the ON ERR logic and continues processing the loop unless the ON ERR logic itself caused the loop to terminate (such as by issuing a BREAK). In the case of the GOSUB, the subroutine exits first and then the ON ERR logic is executed |
|||||
| *Note* | Special processing is allotted to ON ERR ESCAPE. If the first directive in the ON ERR clause is ESCAPE, the system will simply issue an internal ESCAPE when an un-trapped error occurs. | ||||