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 func1()
{
	B b;
	throw b;
}
 
void func2()
{
	A a;
	throw a;
}
 
int main()
{
	try{
		func1();
	}
	catch(...){
		cout<<"Caught All types of exceptions\n";
	}
	try{
		func2();
	}
	catch(B b){
		cout<<"Caught All types of exceptions\n";
	}
}

A. Caught All types of exceptions

B. Caught All types of exceptions
Aborted (core dumped)

C. Error

D. Caught All types of exceptions
Caught All types of exceptions

Answer: Option B


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