Reserving exceptions for abnormal conditions

Like all powerful tools, exceptions can be used to solve all kinds of problems. The first pattern of exception usage therefore tries to limit the damage that would come out of such overuse. When working with exceptions, you should hold back and use them only to signal and handle abnormal conditions. You should not use them to report conditions that can be reasonably expected to happen.

As it is sometimes hard to draw a line between the two, a few real—world examples will help you decide what to do in a specific case.

Hardware exceptions are a good example of exceptions that signal abnormal conditions. In well—written code, a hardware exception such as division by zero or access violation simply ...

Get Hands-On Design Patterns with Delphi 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.