Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
   public:
	A(){}
};
 
class B: public A
{
	int b;
    public:
	B(){}
};
 
void func()
{
	B b;
	throw b;
}
 
int main()
{
	try{
		func();
	}
	catch(B b){
		cout<<"Caught B Class\n";
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
}

A. Caught B Class

B. Caught A Class

C. Compile-time error

D. Run-time error

Answer: Option A


Join The Discussion

Related Questions on Exception Handling in C plus plus

What is exception handling in C++?

A. A method to handle errors during runtime

B. A method to handle errors during compile time

C. A method to handle errors during linking

D. A method to handle errors during execution