Skills101
← All practice quizzes

Quiz: Exception Handling in C++

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

How C++ reports and handles errors with exceptions. try, throw and multiple catch blocks, the standard exception classes, stack unwinding and RAII, writing your own exception class, rethrowing, and noexcept.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    When a throw statement runs inside a try block, what happens to the remaining statements in that try block?

  2. Question 2

    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;
    }
    
  3. Question 3

    Why should you catch exceptions by const reference?

  4. Question 4

    What is stack unwinding?

  5. Question 5

    What does this print?

    #include <iostream>
    #include <stdexcept>
    using namespace std;
    struct G {
        char c;
        G(char x) : c(x) {}
        ~G() { cout << c; }
    };
    void f() {
        G a('1');
        G b('2');
        throw runtime_error("e");
    }
    int main() {
        try { f(); } catch (...) { cout << "C"; }
        return 0;
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →