The next example ONstatement does the same as the first but uses the alternate keywords from the third column of the table:
ON DOUBLE PRECISION DIV 0 CALL div_zero_trap
Table 26 Exceptions handled by the ON statement
Exceptions | Exception keywords | Alternate keywords |
|
|
|
Division by zero | REAL(4) DIV 0 | REAL DIV 0 |
|
|
|
| REAL(8) DIV 0 | DOUBLE PRECISION DIV 0 |
|
|
|
| REAL(16) DIV 0 | (none) |
|
|
|
| INTEGER(2) DIV 0 | INTEGER*2 DIV 0 |
|
|
|
| INTEGER(4) DIV 0 | INTEGER DIV 0 |
|
|
|
Overflow | REAL(4) OVERFLOW | REAL OVERFLOW |
|
|
|
| REAL(8) OVERFLOW | DOUBLE PRECISION OVERFLOW |
|
|
|
| REAL(16) OVERFLOW | (none) |
|
|
|
| INTEGER(2) OVERFLOW | INTEGER*2 OVERFLOW |
|
|
|
| INTEGER(4) OVERFLOW | INTEGER OVERFLOW |
|
|
|
Underflow | REAL(4) UNDERFLOW | REAL UNDERFLOW |
|
|
|
| REAL(8) UNDERFLOW | DOUBLE PRECISION UNDERFLOW |
|
|
|
| REAL(16) UNDERFLOW | (none) |
|
|
|
Invalid (illegal) operation | REAL(4) ILLEGAL | REAL ILLEGAL |
|
|
|
| REAL(8) ILLEGAL | DOUBLE PRECISION ILLEGAL |
|
|
|
CONTROLC | (none) | |
|
|
|
Actions specified by ON
The action taken after an exception is trapped depends on the action specified by the most recently executed ONstatement for that exception. To specify an action, the ON statement must include the keyword ABORT, IGNORE, or CALL. These keywords have the following meanings:
•If ABORTis specified, a standard error message is generated and the program is aborted.
•If IGNOREis specified, processing continues with the next instruction.If the exception is an integer division by zero, the result is set to zero. For other conditions, the previous content of the target register is supplied as the result. IGNOREis particularly useful for preventing
•
If CALLis specified, the normal (ABORT)error message is suppressed, and control is transferred to the specified trap procedure.
Zero or one parameter is passed to the trap procedure. If an argument is specified, it is the result of the operation that took the exception. The procedure can analyze this value to get more precise information, and it can assign another value to the parameter to recover from the error. The type of the argument must be the same as that specified in the keywords. The specified trap procedure is generally an external procedure. However, it is also possible to specify a dummy procedure argument.
The following sections describe how to use the ONstatement to specify different actions to take in the event of an exception.
82 Using the ON statement