HP Fortran Programmer Guide (766160-001, March 2014)

The following sections discuss each of exceptions listed in Table4-1. For more information about
signals, refer to the signal((2))) and signal((5))man pages.
NOTE: Standard Fortran90 provides the IOSTAT=and ERR=specifiers for handling I/O runtime
errors. For information about these specifiers, refer to the descriptions of the I/O statements (for
example, OPENand READ) in the HPFortran Programmer’s Reference. For a descriptive list of the
error messages that can be returned byIOSTAT=, see the HPFortran Programmer’s Reference.
Bus error exception
A bus error exception occurs when a program references an inaccessible memory location, typically
because the reference is to an unaligned or nonexistent address, or because of a hardware failure.
The most likely cause of a bus error is unaligned data reference. A program that passes an array
of (KIND=1) elements to a routine that attempts to access them as (KIND=4)elements may take
a bus error exception. Or if an array of(KIND=1) elements is declared in a common block and
the third element is passed to a routine that attempts to access it as a (KIND=4) variable, the
program will take a bus error exception. For information about the alignment of HP Fortran data
types, see the HPFortran Programmer’s Reference.
Bus errors can occur (as can other exceptions) in any program that generates bad address
references. Although less likely to happen with programs that use the standard Fortran90 pointer,
bad address references can happen when the Cray-style pointer extension is misused or when
Fortran program unit passes a parameter by value to a C routine that attempts to use it as a pointer.
Floating-point exceptions
In accordance with the IEEE Posix Standard, floating-point exceptions are disabled on HP9000
computers. Thus, if a program attempts the following operation:
x = 1.0/0.0
it will not trap it as an exception and will not abort. Instead, the value of a positive infinity (displayed
as +INF) will be assigned to x.
HPFortran provides two compile-line options, +FPand +fp_exception, which enable traps for
floating-point exceptions. The differences between the two options are:
The +fp_exceptionoption enables traps for the following IEEE floating-point exceptions:
Invalid operation
Division by zero
Division by zero
Overflow
Underflow
The +FP option also enables the trap for the inexact operation exception. For detailed descriptions
of these exceptions, see the HP-UX Floating-Point Guide.
Unlike the +fp_exception option, the +FPoption includes a flags argument by which you
can enable specific exceptions.
The +FPoption 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 ONstatement. Although the ONstatement 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” (page 81).
78 Debugging