HP Fortran Programmer Guide (766160-001, March 2014)
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
Alternate keywordsException keywordsExceptions
REAL DIV 0REAL(4) DIV 0Division by zero
DOUBLE PRECISION DIV 0REAL(8) DIV 0
(none)REAL(16) DIV 0
INTEGER*2 DIV 0INTEGER(2) DIV 0
INTEGER DIV 0INTEGER(4) DIV 0
REAL OVERFLOWREAL(4) OVERFLOWOverflow
DOUBLE PRECISION OVERFLOWREAL(8) OVERFLOW
(none)REAL(16) OVERFLOW
INTEGER*2 OVERFLOWINTEGER(2) OVERFLOW
INTEGER OVERFLOWINTEGER(4) OVERFLOW
REAL UNDERFLOWREAL(4) UNDERFLOWUnderflow
DOUBLE PRECISION UNDERFLOWREAL(8) UNDERFLOW
(none)REAL(16) UNDERFLOW
REAL ILLEGALREAL(4) ILLEGALInvalid (illegal) operation
DOUBLE PRECISION ILLEGALREAL(8) ILLEGAL
(none)CONTROLC+Ctrl-C interrupt
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 +Ctrl-C
interrupts at inconvenient times during program execution.
• +Ctrl-C
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