Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1367 |
|
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.