CJCoding With Joseph
15per day
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #48

Bare throw Rethrows

mediumExceptions

What is the output of this code?

📄 Code

1#include <iostream>
2#include <stdexcept>
3using namespace std;
4 
5void inner() {
6 throw runtime_error("inner error");
7}
8 
9void outer() {
10 try {
11 inner();
12 } catch (const runtime_error& e) {
13 cout << "Logging: " << e.what() << endl;
14 throw; // rethrow
15 }
16}
17 
18int main() {
19 try {
20 outer();
21 } catch (const runtime_error& e) {
22 cout << "Caught: " << e.what() << endl;
23 }
24 return 0;
25}