← Back to Question List
C++ Quiz #158
Where catch(...) Has to Go
As written, catch (...) is the LAST handler and the program prints runtime: disk and then something else. What would change if catch (...) were moved ABOVE the std::runtime_error handler?
📄 Code
1#include <iostream>2#include <stdexcept>34void attempt(int kind) {5 try {6 if (kind == 1) {7 throw std::runtime_error("disk");8 }9 throw 42;10 } catch (const std::runtime_error& e) {11 std::cout << "runtime: " << e.what() << "\n";12 } catch (...) {13 std::cout << "something else\n";14 }15}1617int main() {18 attempt(1);19 attempt(2);20 return 0;21}