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 #46

Catch Block Ordering

mediumExceptions

This code has a problem related to the order of catch blocks. What is the issue?

📄 Code

1#include <iostream>
2#include <stdexcept>
3using namespace std;
4 
5int main() {
6 try {
7 throw runtime_error("problem");
8 } catch (const exception& e) {
9 cout << "Base: " << e.what() << endl;
10 } catch (const runtime_error& e) {
11 cout << "Derived: " << e.what() << endl;
12 }
13 return 0;
14}