adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class MyException
    {
        public:
        MyException(int value) : mValue(value)
        {
        }
        int mValue;
    };
    class MyDerivedException : public MyException
    {
        public:
            MyDerivedException(int value, int anotherValue) : MyException(value),    mAnotherValue(anotherValue)
            {
            }
            int mValue;
            int mAnotherValue;
    };
    void doSomething()
    {
        throw MyDerivedException(10,20);
    }
    int main()
    {
        try
        {
            doSomething();
        }
        catch (MyDerivedException &exception)
        {
            cout << "\nCaught Derived Class Exception\n";
        }
        catch (MyException &exception)
        {
            cout << "\nCaught Base Class Exception\n";
        }
        return 0;
    }

a.

Caught Base Class Exception

b.

Caught Derived Class Exception

c.

Caught Base & Derived Class Exception

d.

None of the mentioned

Answer: (b).Caught Derived Class Exception

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?