← Back to Question List
C++ Quiz #144
The Base Handler Comes First
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>34int 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}