HP Fortran Programmer's Guide (September 2007)

Debugging
Handling runtime exceptions
Chapter 4 121
HP Fortran provides two compile-line options, +FP and +fp_exception, which enable traps
for floating-point exceptions. The differences between the two options are:
The +fp_exception option enables traps for the following IEEE floating-point exceptions:
Invalid operation
Division by zero
Overflow
Underflow
The +FP option also enables the trap for the inexact operation exception. For detailed
descriptions of these exceptions, refer to the
HP-UX Floating-Point Guide
.
Unlike the +fp_exception option, the +FP option includes a
flags
argument by which
you can enable specific exceptions.
The +FP option can also be used to enable fast underflow on systems that support it
(chiefly PA2.0 systems).
Both options cause your program to abort when it traps the exception. However,
+fp_exception identifies the type of the exception that occurred and the virtual address
of the statement that triggered it. Also, +FP causes a core dump; +fp_exception does
not.
You can also trap floating-point exceptions with the ON statement. Although the ON statement
requires you to modify source code, it enables you to write trap procedures so that your
program can recover from exceptions. For more information about using the ON statement, see
Chapter 5, “Using the ON statement,” on page 125.
Refer to the
HP Fortran Programmer’s Reference
, for detailed information about the +FP
and +fp_exception options. Also, the
HP-UX Floating-Point Guide
has a useful discussion
of both options and includes detailed information on floating-point exceptions and how to
handle them.
Illegal instruction exception
An illegal instruction exception occurs when a program attempts to execute a bit pattern that
is not an op-code. A common cause of this exception is an overwritten stack. If a program
overwrites the part of the stack that holds the return address, the new (and bad) address may
cause execution control to jump to a memory location that contains data or some other
nonexecutable bit pattern. The attempt to execute this location will result in an illegal
instruction exception.