Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class TestClassA
    {
    };
    class TestClassB : public TestClassA { };
    void Function();
    int main()
    {
    try
    {
    Function();
    }
    catch (const TestClassA&)
    {
    cout << "Caught an exception" << endl;
    }
    return 0;
    }
    void Function()
    {
    throw TestClassB();
    }
    1. Caught an exception
    2. Compilation Error
    3. Runtime Error
    4. Garbage value
    5. None of these
Correct Option: A

In this program, We are arising with the exception by using the method in the class.



Your comments will be displayed only after manual approval.