Exception processing refers to the sequence of events that
takes place when any of the IEEE exception conditions occur. The
standard states that a programmer should be able to enable or disable
the trapping of any of the exception conditions. The standard also
defines default results for all disabled exceptions. For example,
Table 2-11 “Overflow Results Based
on Rounding Mode” shows how
a default result is formulated when an overflow occurs and overflow
traps are disabled.
The
standard also states that a programmer should be able to define
a trap handler for each exception condition. The trap
handler (also called a signal handler)
is a routine that is invoked whenever the particular exception condition
is detected, assuming that trapping for the exception is enabled.
If a program enables trapping but provides no trap handler, a default
handler will be invoked that prints an error message and causes
the process to terminate.
As we noted in “Exception Conditions”, all traps are disabled by default
on HP-UX systems. You can use the fesettrapenable
function, described in “Run-Time Mode Control: The fenv(5)
Suite”, to enable any traps you want to
handle. You can also enable traps through compiler options, which
we discuss in “Command-Line Mode Control: The
+FP Compiler Option”.
On HP-UX systems, the methods for establishing trap handlers
for the IEEE-754 exceptions are the sigaction(2)
routine for C programs and the ON
statement for Fortran programs. See “Math Library Basics” and “Handling Traps” for more information.