When to Provide Your Own Exception/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 Structure Of a Visual Fortran Application,
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 his or her particular needs.
See How to Provide Your Own Exception/Termination Handler for
some ideas on how to deal with unexpected events when implementing
a handler for your application.