Installing an exception handler

The information in this section, except the explanation of the -qsigtrap option, applies both to SIGTRAP and SIGFPE signals. When a program that uses the XL Fortran or AIX® exception-detection facilities encounters an exception condition, it receives a signal from the operating system. This causes a branch to whatever handler is specified by the program.

By default, the program stops after producing a core file, which you can use with a debugger to locate the problem. If you want to install a SIGTRAP signal handler, use the -qsigtrap option. It allows you to specify an XL Fortran handler that produces a traceback or to specify a handler you have written:
xlf95 -qflttrap=ov:und:en pi.f                             # Dump core on an exception
xlf95 -qflttrap=ov:und:en -qsigtrap pi.f                   # Uses the xl__trce handler
xlf95 -qflttrap=ov:und:en -qsigtrap=return_22_over_7 pi.f  # Uses any other handler
You can also install an alternative exception handler, either one supplied by XL Fortran or one you have written yourself, by calling the SIGNAL subroutine (defined in /usr/include/fexcp.h):
  INCLUDE 'fexcp.h'
  CALL SIGNAL(SIGTRAP,handler_name)
  CALL SIGNAL(SIGFPE,handler_name)
The XL Fortran exception handlers and related routines are:
xl__ieee
Produces a traceback and an explanation of the signal and continues execution by supplying the default IEEE result for the failed computation. This handler allows the program to produce the same results as if exception detection was not turned on.
xl__trce
Produces a traceback and stops the program.
xl__trcedump
Produces a traceback and a core file and stops the program.
xl__sigdump
Provides a traceback that starts from the point at which it is called and provides information about the signal. You can only call it from inside a user-written signal handler, and it requires the same parameters as other AIX signal handlers. It does not stop the program. To successfully continue, the signal handler must perform some cleanup after calling this subprogram.
xl__trbk
Provides a traceback that starts from the point at which it is called. You call it as a subroutine from your code, rather than specifying it with the -qsigtrap option. It requires no parameters. It does not stop the program.

All of these handler names contain double underscores to avoid duplicating names that you declared in your program. All of these routines work for both SIGTRAP and SIGFPE signals.

You can use the -g compiler option to get line numbers in the traceback listings. The file /usr/include/fsignal.h defines a Fortran derived type similar to the ucontext_t structure in /usr/include/sys/ucontext.h. You can write a Fortran signal handler that accesses this derived type.

Sample programs for exception handling lists some sample programs that illustrate how to use these signal handlers or write your own. Also see the SIGNAL procedure in the XL Fortran Language Reference for more information.