Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class MyException
4.
{
5.
public:
6.
MyException(int value) : mValue(value)
7.
{
8.
}
9.
int mValue;
10.
};
11.
class MyDerivedException : public MyException
12.
{
13.
public:
14.
MyDerivedException(int value, int anotherValue) : MyException(value), mAnotherValue(anotherValue)
15.
{
16.
}
17.
int mValue;
18.
int mAnotherValue;
19.
};
20.
void doSomething()
21.
{
22.
throw MyDerivedException(10,20);
23.
}
24.
int main()
25.
{
26.
try
27.
{
28.
doSomething();
29.
}
30.
catch (MyDerivedException &exception)
31.
{
32.
cout
Options:
A .  Caught Base Class Exception
B .  Caught Derived Class Exception
C .  Both a & b
D .  None of the mentioned
Answer: Option B

As we are throwing the value from the derived class, it is arising an exception in derived class
Output:
$ g++ class1.cpp
$ a.out
Caught Derived Class Exception



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers