-
What is the output of this program?
#include <iostream>
using namespace std;
class ExceptionClass
{
public:
ExceptionClass(int value) : mValue(value)
{
}
int mValue;
};
class DerivedExceptionClass : public ExceptionClass
{
public:
DerivedExceptionClass(int value, int anotherValue) : ExceptionClass(value),mAnotherValue(anotherValue)
{
}
int mValue;
int mAnotherValue;
};
void doSomething()
{
throw DerivedExceptionClass(10,20);
}
int main()
{
try
{
doSomething();
}
catch (DerivedExceptionClass &exception)
{
cout << "Caught Derived Class Exception";
}
catch (ExceptionClass &exception)
{
cout << "Caught Base Class Exception";
}
return 0;
}
-
- Caught Base Class Exception
- Compilation Error
- Caught Derived Class Exception
- Runtime Error
- None of these
Correct Option: C
As we are throwing the value from the derived class, it is arising an exception in derived class