HP Fortran Programmer's Guide (September 2007)

Debugging
Handling runtime exceptions
Chapter 4 119
Handling runtime exceptions
Broadly defined, an exception is an error or fault condition that affects a program’s results.
Exceptions can range from the relatively benign inexact result condition that occurs in certain
floating-point operations to the more severe segmentation violation that occurs when a
runaway program attempts to access unallocated memory.
Exceptions that threaten the integrity of the operating system can cause HP-UX to raise an
exception signal (for example, SIGSEGV for a segmentation violation) so that the process can
take appropriate action to recover from the exception. Such exceptions may cause the
program that took the exception to abort, but not necessarily. By trapping an exception—that
is, by catching the signal—a program may handle the exception, if only by aborting when it
occurs.
There are also a well-defined set of floating-point conditions that, although they pose no
threat to the operating system, can also cause an exception—for example, dividing a
floating-point number by zero. By default, traps for floating-point exceptions are disabled on
HP 9000 computers, but they can be enabled by +fp_exception and +FP options. (You can
also use the ON statement to enable traps for floating-point exceptions.)
Programs that have been compiled with the +fp_exception option can trap the exceptions
listed in Table 4-1. Any of the exceptions listed in the second column will cause the operating
system to generate the signal listed in the first column. Programs compiled with +FP can trap
specific floating-point exceptions (SIGFPE).
When a program compiled with +fp_exception takes an exception, the following events
occur:
The program traps the exception.
Table 4-1 Signals recognized by +fp_exception
Signal Exception
SIGBUS Bus error instruction
SIGFPE Floating-point exceptions
SIGILL Illegal instruction
SIGSEGV Segmentation violation or memory fault
SIGSYS Bad argument to a kernel system call