Correct Answer is : compile time error
7. Where should we place catch block of the derived class in a try-catch block?
Correct Answer is : /* …. */
8. What happens when this C++ program is compiled?
#include
#include
#include
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";
}
}
A. distinguishes between comments and code
B. r distinguishes between comments and outer data
Correct Answer is : distinguishes between comments and code
9. What is the output of the following C++ code?
#include
#include
#include
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";
}
}
Correct Answer is : segmentation fault
10. What is the output of the following C++ code?
#include
#include
#include
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";
}
}
11. What is the output of the following C++ code?
#include
#include
#include
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";
}
}
12. What id the syntax for catching any type of exceptions?
A. It will not return value to its caller
B. It will return value to its caller
C. Maybe or may not be return value to its caller
Correct Answer is : It will not return value to its caller
13. What is the output of the following C++ code?
#include
#include
#include
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";
}
}
Correct Answer is : 45337
14. Uncaught exception leads to ______________
15. An uncaught handler returns to _______________
A. complex variable_name;
B. complex variable_name;
C. Complex variable_name;
D. Complex variable_name;
Correct Answer is : complex variable_name;
16. Header file used for exception handling in C++?
Correct Answer is : real()
17. The C++ code which causes abnormal termination/behaviour of a program should be written under _________ block.
Correct Answer is : imag()
18. Exception handlers are declared with ____________ keyword.
A. Complex number is: 3 + 5i
B. Complex number is: 5 + 3i
C. Complex number is: 9 + 25i
D. Complex number is: 3 – 5i
Correct Answer is : Complex number is: 3 + 5i
19. Which of the following statements are correct about Catch handler?
i. It must be placed immediately after the try block
ii. It can have more than one parameters
iii. There must be one and only one catch handler for every try block
iv. There can be multiple catch handler for a try block
v. General catch handler can be kept anywhere after try block.
Correct Answer is : abs()
20. In nested try-catch block, if the inner catch block gets executed, then______________
D. Absolute value is: 5.83095
Correct Answer is : Absolute value is: 5.83095