10 Exceptions and Resources
This chapter covers:
- Downsides to exception usage
- Benefits of good exception usage
- The relationship between resource handling and exceptions
- Building an exception hierarchy for precise control
The topic of exceptions has proponents and detractors across the entire spectrum, advocating from rarely, if ever, to using them all the way to using them frequently. Over the years, several authors have published articles arguing for various positions between these. Many of these arguments are relevant, yet they mesh poorly with other viewpoints. This situation leaves us in a quandary of approaching exception usage. Many of the positions are correct but incomplete. There are numerous situations where one policy is meaningful but would make little sense in others.
Exceptions need to be considered in the scope of the entire program. A policy that addresses the behavior of a function may not be meaningfully extended to larger units. Many current programs running in production need to have the luxury of redesigning to handle a unified strategy for exceptions. In these myriad cases, almost any design is better than none. Yet, integrating localized strategies into larger units may prove frustrating and error-prone.