Thoughts on Exception Design

Before getting into the details of exception design, consider a facet that the simple examples in this chapter cannot communicate. Your overall exception handling strategy should guide the design and handling of your exceptions at the lowest levels. At least a napkin sketch of your exception handling architecture goes a long way to save you pain in the future. The following are some questions to consider.

• Will you handle exceptions at the top-most boundary layers such as UI, API, and service interfaces (my recommendation) or at lower levels in a more ad hoc fashion?

• In languages like Java in which the distinction is relevant, should you implement exceptions as checked exceptions that are declared as part of the ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.