"Poor exception-handling implementations can thwart even the best design"
Rebecca J. Wirfs-Brock
Exception Handling Strategies
- Coding Errors should not be handled by exception, but treated by proper testing strategies (e.g., unit-tests)
- The number of "own" exception classes should be very limited
- Naming of these exception classes should reflect what happened, not where the exception was raised
- Recasting exceptions has to be done with care: just repeatedly rethrow exceptions is typically not a good idea (also from the performance point of view); on the other hand, throwing exceptions too deep in the hierarchy can leak implementation details (and confuse users)
- Hence exception should be enriched with context information (from the classes that know the context) but thrown at a position, where the user is provided with useful information
She suggests the development of exception patterns and anti-patterns (comparably to the well-known software patterns). Some attempts can be found at the Exception Pattern Wiki, and at this article, dealing with exception anti-patterns.