HP Fortran Programmer's Guide (B3908-90031; September 2011)

Using the ON statement
Allowing core dumps
Chapter 5 139
Allowing core dumps
If a program includes the ON statement and takes an exception other than the one specified by the exception
keywords, the program will abort with a procedure traceback but without a core dump. If you want to allow
a core dump for one or more signals for a program that includes the ON statement, you must revise the
program for each such signal.
For example, you may wish to handle floating-point exceptions with the ON statement, but still allow a core
dump for other signals (for example, a bus error). The following example program uses the SIGNAL routine
in the libU77 library to reset the default behavior for a bus error signal. The program uses the ON
statement to handle floating-point exceptions, but allows a core dump when a bus error occurs:
Example 5-5 allow_core.f90
PROGRAM main
ON REAL OVERFLOW IGNORE
CALL take_err
END PROGRAM main
SUBROUTINE take_err
DOUBLE PRECISION :: d
POINTER (ip, d) ! Cray-style pointer
REAL :: x, y
INTEGER, PARAMETER :: sigbus=10, sigdfl=0
INTEGER :: sigrtn, SIGNAL
! Set the action for bus error to be the default (DUMP CORE),
! overriding the action of issuing a procedure traceback
! that is established by using the ON statement.
! To suppress the core dump and enable a procedure traceback,
! comment out the next statement
sigrtn = SIGNAL(sigbus, 0, sigdfl)
x = 1.0E38
x = y * 10.0 ! causes a real overflow
! Bus error is caused by the next statements
ip = MALLOC(40)
ip = ip + 4 ! ip is now 4-byte aligned
d = 99.0 ! bus error
END SUBROUTINE take_err
This program must be compiled with the +U77 option to link in the libU77 library. Here is the command
line and the output from a sample run: