HP Fortran Programmer's Guide (September 2007)
Using the ON statement
Exceptions handled by the ON statement
Chapter 5 127
Exceptions handled by the ON statement
Like the +fp_exception option, the ON statement enables traps for floating-point exceptions
(by default, traps for floating-point exceptions are disabled on HP 9000 computers). When
traps are enabled, an executing program that takes any of the following exceptions will abort,
unless an ON statement specifies a different action:
• Division by zero
• Overflow
• Underflow
• Inexact result
• Invalid (or illegal) operation
These exceptions are defined by the IEEE standard for floating-point operations. The ON
statement enables traps for these exceptions, regardless of whether the exception is taken by
user code or by a call to a library routine. In addition, the ON statement also enables traps for
integer division by zero, integer overflow, and +Ctrl-C interrupts. The +Ctrl-C interrupt
occurs when the user presses +Ctrl-C during program execution.
Table 5-1 on page 127 lists the exceptions handled by the ON statement and gives the
keywords that must be specified in the ON statement to indicate the exception being handled.
The first column indicates the type of exception. The second column gives the keywords that
must appear in the ON statement, immediately following the word ON. The third column gives
alternate keywords you can specify instead of those in the second column.
For example, the following ON statement will trap attempts to divide by zero with 8-byte
floating-point operands:
ON REAL(8) DIV 0 CALL div_zero_trap
The next example ON statement 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 5-1 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