- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm trying to implement a floating point error handler with the main program in Fortran. So I started with the example provided (GETEPTRS_S2.F90, see "Exceptions" folder in V9 examples provided at top of this board), which essentially sets up the signal handler hand_fpe for the signal SIG$FPE. The resulting behavior is the same as in my real application, namely: 1) when using RAISEQQ to force the SIG$FPE signal, the handler (and traceback) works beautifully, but if I generate a "real" divide-by-zero (as done in the example), the handler is not called (and the OS puts up an error dialog instead).
Here is my main test Fortran program (maintestfpe.f), which essentially calls the example functions (from file GETEPTRS_S2.F90). The call to FOR_SET_FPE essentially duplicates the /fpe:0 compiler option (masking to enable trapping of FPE errors), and can be commented out -- with the same result.
program main
USE DFLIB
real*4 a, b
integer status
integer(4)::FPE_STS=0, FPE_MASK=0
integer(4) set_handler
real(4) geteptrs_s2
b = 0.0
C Enable FPE trapping for overflow, div-by-zero, and invalid
FPE_MASK = FPE_M_TRAP_OVF + FPE_M_TRAP_DIV0 + FPE_M_TRAP_INV
FPE_STS = FOR_SET_FPE(FPE_MASK)
C Setup error handler
status = set_handler()
write(6,*) 'After set_handler...'
C Generate FPE error (div by zero)
a = geteptrs_s2(b)
end
Here is my compile/link statement (using Intel Fortran 8.1, but same behavior occurs using 9.0):
ifort /MD /Qsave /fpe:0 /extend_source /Zi /traceback maintestfpe.f geteptrs_s2.f90
Thanks for any suggestions!
I'm trying to implement a floating point error handler with the main program in Fortran. So I started with the example provided (GETEPTRS_S2.F90, see "Exceptions" folder in V9 examples provided at top of this board), which essentially sets up the signal handler hand_fpe for the signal SIG$FPE. The resulting behavior is the same as in my real application, namely: 1) when using RAISEQQ to force the SIG$FPE signal, the handler (and traceback) works beautifully, but if I generate a "real" divide-by-zero (as done in the example), the handler is not called (and the OS puts up an error dialog instead).
Here is my main test Fortran program (maintestfpe.f), which essentially calls the example functions (from file GETEPTRS_S2.F90). The call to FOR_SET_FPE essentially duplicates the /fpe:0 compiler option (masking to enable trapping of FPE errors), and can be commented out -- with the same result.
program main
USE DFLIB
real*4 a, b
integer status
integer(4)::FPE_STS=0, FPE_MASK=0
integer(4) set_handler
real(4) geteptrs_s2
b = 0.0
C Enable FPE trapping for overflow, div-by-zero, and invalid
FPE_MASK = FPE_M_TRAP_OVF + FPE_M_TRAP_DIV0 + FPE_M_TRAP_INV
FPE_STS = FOR_SET_FPE(FPE_MASK)
C Setup error handler
status = set_handler()
write(6,*) 'After set_handler...'
C Generate FPE error (div by zero)
a = geteptrs_s2(b)
end
Here is my compile/link statement (using Intel Fortran 8.1, but same behavior occurs using 9.0):
ifort /MD /Qsave /fpe:0 /extend_source /Zi /traceback maintestfpe.f geteptrs_s2.f90
Thanks for any suggestions!
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try adding a print statement to print the value of variable a after the call to geteptrs_s2. See if that helps.
Thanks,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the suggestion, unfortunately, this did not help. :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you see the error dialog, are you running the program in the debugger or just in a console window?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Its being executed from a console window. The error dialog that comes up is a standard Windows OS termination dialog. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It sounds to me like SIGNALQQ is not establishing your handler with the C rtl. If you are comfortable coding up a call to the C rtl sigaction routine, you could try bypassing SIGNALQQ in that way.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page