← Back to Question List
C++ Quiz #134
Which Family invalid_argument Belongs To
A std::invalid_argument is thrown and there are two handlers. Which one runs, and why?
📄 Code
1#include <iostream>2#include <stdexcept>34int main() {5 try {6 throw std::invalid_argument("bad flag");7 } catch (const std::logic_error& e) {8 std::cout << "logic error: " << e.what() << "\n";9 } catch (const std::runtime_error& e) {10 std::cout << "runtime error: " << e.what() << "\n";11 }12 return 0;13}