18.1.1. Throwing an Exception
In C++, an exception is raised by throwing an expression. The type of the thrown expression, together with the current call chain, determines which handler will deal with the exception. The selected handler is the one nearest in the call chain that matches the type of the thrown object. The type and contents of that object allow the throwing part of the program to inform the handling part about what went wrong.
When a throw
is executed, the statement(s) following the throw
are not executed. Instead, control is transferred from the throw
to the matching catch
. That catch
might be local to the same function or might be in a function that directly or indirectly called the function in which the exception occurred. The ...
Get C++ Primer, Fifth Edition 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.