| Version 1.9 Build 1556
|
|
Next: Interface
Up: Exceptions
Previous: Exceptions
The main intent of this paper is to provide a user level introduction to
the C++ exception mechanism with a basic introduction to the
way it is used in aips++. This should allow developers to use the mechanism.
C++ provides a standard method to handle exceptional conditions. When
such conditions arise, control is transferred to a code block which
can handle the exception, if one exists. If no handler exists which is capable
of handling the exception, the program is aborted. This package handles
cleaning up the call stack which may have been created between when the handler
was installed and when the exception was thrown. In addition, any
objects which were created on the stack during this period will be deleted.
This provides a mechanism for transferring control from the point where an
exceptional condition occurs to the code to handle the exception without
memory leaks. Some of the advantages of this approach are:
- The code to display the error message can be moved out to the appropriate
level. Otherwise, the code to display an error message might have to be
deep within an application in a place which could otherwise be independent
of the graphical user interface. Without exceptions error messages must be
carefully propagated out via return values until the appropriate level for
their display is reached.
- The exception mechanism allows for an incremental graceful exit. The same
exception can be thrown a number of times so that each layer of the program
can have a chance to respond to the exception as appropriate. This can be
important for maintaining the integrity of portions of the program, e.g.
the user interface or database portions.
- Using exceptions a program can continue after an error even though
the error may have been fatal at the point where it occurs. In a more
traditional approach, this would require careful checks of return codes.
So while everything which can be accomplished with exceptions can be
accomplished with returned error codes or other traditional approaches, the
use of exceptions is cleaner.
Next: Interface
Up: Exceptions
Previous: Exceptions
  Contents
  Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc.,
Washington, D.C.
Return to AIPS++ Home Page
2006-10-15