17.5 When to Use Exception Handling

Exception handling is designed to process synchronous errors, which occur when a statement executes, such as invalid function parameters and unsuccessful memory allocation (due to lack of memory). Exception handling is not designed to process errors associated with asynchronous events (e.g., disk I/O completions, network message arrivals, mouse clicks and keystrokes), which occur in parallel with, and independent of, the program’s flow of control.

Complex applications normally consist of predefined software components (such as classes from the Standard Library) and application-specific components that use the predefined components. When a predefined component encounters a problem, that component needs a mechanism ...

Get C++ How to Program, 10/e 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.