HP Fortran Programmer's Guide (March 2010)

Using the ON statement
Actions specified by ON
Chapter 5 135
Actions specified by ON
The action taken after an exception is trapped depends on the action specified by the most
recently executed ON statement 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 ABORT is specified, a standard error message is generated and the program is aborted.
•If IGNORE is 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.
IGNORE is particularly useful for preventing +Ctrl-C interrupts at inconvenient times
during program execution.
•If CALL is 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 ON statement to specify different actions to take
in the event of an exception.
Terminating program execution
Use the ABORT form of the CALL statement to terminate the program when an exception
occurs. In the following example, the log is taken of a negative number. The ABORT clause
causes the program immediately after the exception is detected and to issue a procedure
traceback:
Example 5-1 abort.f90
PROGRAM main
REAL :: x, y, z
! The next statement enables traps for floating-point exceptions
! and specifies the action to take for divide by zero.