"Poor exception-handling implementations can thwart even the best design"
Rebecca J. Wirfs-Brock
Exception Handling Strategies
In the recent issue of IEEE Software, Rebecca J. Wirfs-Brock discusses the influence of exception handling strategies on the quality of software architecture (PDF can be found here). In the article she expresses some design-guidelines
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.
- 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.
No comments:
Post a Comment