5 Using the ON statement
Whenever a runtime error occurs, the default action of your program depends on the type of the error. If the error results from a
As described in “Handling runtime exceptions” (page 77), the +fp_exception and +FPoptions provide control over how a program behaves when a runtime error occurs. The ON statement provides an additional level of control by enabling your program to handle
•The type of the exception
•One of the following actions:
❏Execute a trap procedure
❏Ignore the interrupt
❏Abort the program
The action specified by the ON statement can only be changed by another ON statement that specifies the same exception.
This chapter describes how to use the ON statement. The syntax of the ON statement is described in the HPFortran Programmer’s Reference. For detailed information about trapping math errors, see the
NOTE: If you include theON statement in a program that you optimize at level 2 or higher and the program takes an exception, the results may vary from those you would get from an unoptimized program or from a program that didn’t have the ONstatement.
Exceptions handled by the ON statement
Like the +fp_exceptionoption, the ONstatement enables traps for
•Division by zero
•Overflow
•Underflow
•Invalid (or illegal) operation
These exceptions are defined by the IEEE standard for
For example, the following ONstatement will trap attempts to divide by zero with
ON REAL(8) DIV 0 CALL div_zero_trap
Exceptions handled by the ON statement 81