← Quiz: Exception Handling in C++: all 10 questions
Quiz: Exception Handling in C++ · Question 2 of 10
What does this print? (code)
What does this print?
#include <iostream>
#include <stdexcept>
using namespace std;
int main() {
try {
cout << "A";
throw out_of_range("x");
cout << "B";
} catch (const invalid_argument &) {
cout << "C";
} catch (const exception &) {
cout << "D";
}
cout << "E";
return 0;
}
- A.ABDE
- B.ACE
- C.ADE
- D.AD
Answer & explanation
Correct answer: ADE
out_of_range is not an invalid_argument, so the general exception handler runs (D), then execution continues after the try/catch (E).
Can you get the rest right without peeking?
Take the timed Quiz: Exception Handling in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →