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

Throw and Catch a Runtime Error

easyExceptions

📄 Code

Read carefully — what does this print?
1#include <iostream>
2#include <stdexcept>
3 
4int main() {
5 try {
6 std::cout << "opening the vault\n";
7 throw std::runtime_error("wrong code");
8 } catch (const std::exception& e) {
9 std::cout << "caught: " << e.what() << "\n";
10 }
11 std::cout << "done\n";
12 return 0;
13}

🎯 Your Answer