CJCoding With Joseph
15free / daySign inCreate account
← 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 #144

The Base Handler Comes First

mediumExceptions

A std::runtime_error is thrown, and the handler for std::exception is written BEFORE the handler for std::runtime_error. Which handler runs?

📄 Code

1#include <iostream>
2#include <stdexcept>
3 
4int main() {
5 try {
6 throw std::runtime_error("disk error");
7 } catch (const std::exception& e) {
8 std::cout << "general: " << e.what() << "\n";
9 } catch (const std::runtime_error& e) {
10 std::cout << "specific: " << e.what() << "\n";
11 }
12 return 0;
13}