13.7. Unexpected Exceptions

Exception specifications state which exceptions a function may throw, either directly or indirectly. When a function throws an exception that does not appear in the function's exception specification, the exception is unexpected. By default, the exception mechanism calls unexpected(), which calls terminate() to stop your program. This section explores unexpected exceptions in more detail and shows you strategies for handling them in applications.

The unexpected() Function

The exception mechanism calls unexpected() for thrown exceptions that do not appear in a function's exception specification. The unexpected() function executes abort(), which terminates your program without calling any object destructors. The set_unexpected() ...

Get Navigating C++ and Object-Oriented Design 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.