Locating where the exception occurred requires exception trapping be enabled. This can be done by either compiling with the -ftrap=common option (the default when compiling with f95) or by establishing an exception handler routine with ieee_handler(). With exception trapping enabled, run the program from dbx, using the dbx catch FPE command to see where the error occurs.
The advantage of compiling with -ftrap=common is that the source code need not be modified to trap the exceptions. However, by calling ieee_handler() you can be more selective as to which exceptions to look at.
Example: Compiling for and using dbx:
demo% f95 -g myprogram.f demo% dbx a.out Reading symbolic information for a.out ... (dbx) catch FPE (dbx) run Running: a.out (process id 19739) signal FPE (floating point divide by zero) in MAIN at line 212 in file "myprogram.f" 212 Z = X/Y (dbx) print Y y = 0.0 (dbx) |
If you find that the program terminates with overflow and other exceptions, you can locate the first overflow specifically by calling ieee_handler() to trap just overflows. This requires modifying the source code of at least the main program, as shown in the following example.
Example: Locate an overflow when other exceptions occur:
To be selective, the example introduces the #include, which required renaming the source file with a .F suffix and calling ieee_handler(). You could go further and create your own handler function to be invoked on the overflow exception to do some application-specific analysis and print intermediary or debug results before aborting.