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 #134

Which Family invalid_argument Belongs To

easyExceptions

A std::invalid_argument is thrown and there are two handlers. Which one runs, and why?

📄 Code

1#include <iostream>
2#include <stdexcept>
3 
4int 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}