What is Re-throwing an exception means in C++?
Select an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
68
Questions
4/4
Page
Pick an option on a question to see the right answer and solution.
Select an option to see the answer and solution.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void func(int a, int b)
{
if(b < 1){
throw b;
}
else{
cout<<"Product of "<<a<<" and "<<b<<" is: "<<a*b<<endl;
}
}
int main()
{
try
{
try
{
func(5,-1);
}
catch(int b)
{
if(b==0)
throw "value of b is zero\n";
else
throw "value of b is less than zero\n";
}
}
catch(const char* e)
{
cout<<e;
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
#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";
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
#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(A a){
cout<<"Caught A Class\n";
}
catch(B b){
cout<<"Caught B Class\n";
}
}Select an option to see the answer and solution.
#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(A a){
cout<<"Caught A Class\n";
}
catch(B b){
cout<<"Caught B Class\n";
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.