Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1367
News FAQ
Search Home


next up previous
Next: What exception to throw Up: Note 190: Exceptions Changes for AIPS++ Previous: Exception mechanism

When to throw an exception

Exceptions are intended to be used in exceptional circumstances -- those that the application programmer cannot reasonably be expected to test for -- not as an alternative return mechansim. If nothing else, throwing an exception is expensive: Meyers2notes that throwing an exception might be three orders or magnitude more expensive than a normal function return.

As a rule of thumb then, a library routine should rarely have a catch clause. Anticipated problems should be handled with normal programming constructs (error returns and the like). The AIPS++ library already follows this rule.

Looging through the aips package, an exception is thrown3 in about 1800 places. Examining about half of these reveals the following reasons that exceptions are thrown:

Argument checking 45%
Internal invariant/state verification 40%
Memory allocation 10%
I/O errors 2.5%
Misc. 2.5%

It seems to me that we are generally throwing exceptions appropriately.

The only errors that a running program might plausibly be able to handle (other than via a graceful exit or a next iteration of a high level loop) are the memory allocation and I/O errors.


next up previous
Next: What exception to throw Up: Note 190: Exceptions Changes for AIPS++ Previous: Exception mechanism
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-03-28