Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

Provide Your Own Exception or Termination Handler

For Fortran Console, Fortran QuickWin, and Fortran Standard Graphics applications, the default exception and termination handlers are probably sufficient to meet most needs. As described in Handlers for the Application (Project) Types, Fortran DLL and Fortran Windows* applications do not have default handlers.

Whenever the default exception and termination handlers do not meet all your needs, consider providing your own handler. This is really a question you need to answer for each specific application. Some examples:

  • Suppose your application creates some files during the course of its execution and you do not want to leave them on the disk if an unexpected error or exception occurs. The default termination actions only cause the files to be closed if you specifically opened them with DISPOSE='DELETE'. But suppose you do not want them deleted under normal termination. If an unexpected event occurs, you need to get control so you can clean up these files as needed.

  • Perhaps your application can recover from a particular situation, for example, an integer divide-by-zero operation. You want to gain control if that exception occurs and deal with it.

  • Perhaps you just want to output an application-specific error message when an exception occurs.

  • You are building a Fortran DLL to run under a Visual Basic* GUI and you do not want the DLL to crash the application if an exception occurs in the DLL.

  • Your code takes a lock on a global resource and you want to be sure and release the resource if an unexpected event occurs.

The list of possibilities is endless and only the application developer can anticipate particular needs.

The most general way to establish your own handler is to use Windows* structured exception handling capabilities (SEH). For lighter-weight exception handling requirements, you can use SIGNALQQ.