HP-UX Floating-Point Guide
Chapter 6 161
Floating-Point Trap Handling
Handling Traps
The ON statement is documented fully in the HP Fortran 90
Programmer’s Reference and the HP FORTRAN/9000 Programmer’s
Guide.
Using the sigaction(2) Function (C only)
For C programs, the standard method of handling errors is to use the
sigaction(2) function. The function establishes the address of a
signal-handling function that is called whenever the specified HP-UX
signal is raised. The major problem with this method is that there is only
one HP-UX signal, SIGFPE, for all IEEE and integer exceptions. When
SIGFPE is raised, the only way to find out which exception generated the
signal is to examine the floating-point exception registers, which can be
obtained from the sigcontext structure that is an argument to the
sigaction(2) function. (Or you can enable a trap for only one exception.)
The following C program uses fesettrapenable to enable a trap for
the overflow exception, and calls sigaction(2) to specify that the function
handle_sigfpe is to be called when SIGFPE is raised.