CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
C++ Code Walkthrough #130

A New Exception From Inside a Catch

hardExceptions

📄 Code

Read carefully — what does this print?
1#include <iostream>
2#include <stdexcept>
3 
4int main() {
5 try {
6 try {
7 throw std::runtime_error("disk read failed");
8 } catch (const std::runtime_error& e) {
9 std::cout << "low level: " << e.what() << "\n";
10 throw std::logic_error("could not load settings");
11 }
12 std::cout << "settings loaded\n";
13 } catch (const std::exception& e) {
14 std::cout << "high level: " << e.what() << "\n";
15 }
16 std::cout << "continuing with defaults\n";
17 return 0;
18}

🎯 Your Answer