... handler (lines 14–18) catches this exception, prints an error message (lines 15–16) and rethrows the exception (line 17). This terminates the function and returns control to line 27 in the try block in main. The try block terminates (so line 28 does not execute), and the catch handler in main (lines 30–32) catches this exception and prints an error message (line 31). Since we do not use the exception parameters in this example’s catch handlers, we omit the exception parameter names and specify only the type of exception to catch (lines 14 and 30).

Fig. 17.3 Rethrowing an exception.

Alternate View

 1   // Fig. 17.3: fig17_03.cpp
 2   // Rethrowing ...

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.