18.1.3. Function try
Blocks and Constructors
In general, exceptions can occur at any point in the program’s execution. In particular, an exception might occur while processing a constructor initializer. Constructor initializers execute before the constructor body is entered. A catch
inside the constructor body can’t handle an exception thrown by a constructor initializer because a try
block inside the constructor body would not yet be in effect when the exception is thrown.
Exercise 18.4: Looking ahead to the inheritance hierarchy in Figure 18.1 (p. 783), explain what’s wrong with the following try
block. Correct it.
try { // use of the C++ standard library} catch(exception) { // ...} catch(const runtime_error ...
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.