Exceptions
Exception handling provides a way of transferring control and information from some point in the execution of a program to a handler associated with a point previously passed by the execution (in other words, exception handling transfers control up the call stack).
Evaluating a throw expression will throw an exception. Exceptions can also be thrown in other contexts.
In order for an exception to be caught, the throw expression has to be inside a try block, and the try block has to contain a handler that matches the type of the exception object.
When declaring a function, the following specification(s) may be provided to limit the types of the exceptions a function may throw:
| (until C++17) |
| (since C++11) |
Errors that arise during exception handling are handled by std::terminate and std::unexpected(until C++17).
Contents |