Use Windows* Structured Exception Handling

Windows* provides a robust exception and termination handling mechanism called Structured Exception Handling (SEH). Structured exception handling requires support in both the operating system and compilers. Unfortunately, Intel® Fortran does not include extensions for SEH support, but you can still take advantage of this powerful tool. By introducing a bit of C code in your application, you can use SEH to meet your exception handling needs.

A good reference on this subject is Chapter 16 in the book Advanced Windows (Third Edition) by Jeffrey Richter.

Custom Handlers for Fortran Console, Fortran QuickWin, and Fortran Standard Graphics Applications

Fortran Console and Fortran QuickWin (and Fortran Standard Graphics) applications have the full benefit of the Fortran default exception and error handling processing facilities. You may, however, want to supplement or replace the default facilities.

Contain Errors and Exceptions in Fortran DLL Applications

If you are building a Fortran DLL and intend to call it from a main program written in some other language, you want to be careful that errors and exceptions in the DLL do not crash your main application.

Here are a few basic principles to keep in mind if you are building a Fortran DLL:

Enable Floating-point Traps in Fortran DLL Applications

Before you can worry about how you will handle a floating-point trap condition occurring in a DLL, you have to consider the problem of unmasking those traps so they can occur. If you are compiling with fpe[:]3 and polling the floating-point status word to check for exceptions, you do not have to worry about the problem of unmasking traps. You do not want traps unmasked in that case.

If your strategy is to compile with fpe[:]0 and allow traps on floating-point exceptions, you need to take action to unmask the traps in the floating-point control word because most other languages mask traps by default.

Recall that a Fortran Console or Fortran QuickWin (or Standard Graphics) application would automatically have unmasked traps for you because the Fortran runtime system provides the main program and calls your MAIN__, which executes some prolog code before the actual application code starts.

You do not have that in a Fortran DLL called by some other language. Different languages establish different initial environments. You must provide the desired initial environment yourself.

Custom Handlers for Fortran Windows* Applications

Fortran Windows* applications are not hooked up to the Fortran default exception handling processing facilities. Fortran Windows* applications are considered to be an area devoted to full customization, and the Fortran runtime system tries to "stay out of the way," so you can do whatever you want in your code.

See Also