🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.ABDE
  2. B.ACE
  3. C.ADE
  4. 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 →