CJCoding With Joseph
15free / daySign inCreate account
Back to Multiple Choice Quiz

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

Topics

Catch Block Ordering

C++ quiz · Question 46
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}