Chapter 7. Exceptions

There are many benefits to exception handling as compared to return-value-based error reporting. Good framework design helps the application developer realize the benefits of exceptions. This section discusses the benefits of exceptions and presents guidelines for using them effectively.

  • Exceptions promote API consistency. This is because they are designed to be used for failure reporting and nothing else. In contrast, return values have many uses, of which failure reporting is only a subset. For this reason, it is likely that APIs that report failure through return values will find a number of patterns, whereas exceptions can be constrained to specific patterns. The Win32 API is a clear example of this inconsistency through ...

Get Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries 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.