Question
#include <iostream>
using namespace std;
class Base
{
protected:
int a;
public:
Base()
{
a = 34;
}
Base(int i)
{
a = i;
}
virtual ~Base()
{
if (a < 0) throw a;
}
virtual int getA()
{
if (a < 0)
{
throw a;
}
}
};
int main()
{
try
{
Base b(-25);
cout << endl << b.getA();
}
catch (int)
{
cout << endl << "Illegal initialization";
}
}
a.
Illegal initialization
b.
Terminate called after throwing an instance of ‘int’
c.
Illegal initialization & terminate called after throwing an instance
d.
None of the mentioned
Posted under Object Oriented Programming Using C++
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the output of this program?
Similar Questions
Discover Related MCQs
Q. What function will be called when we have a uncaught exception?
View solution
Q. What will not be called when the terminate() is arised in constructor?
View solution
Q. What will happen when we move try block far away from catch block?
View solution
Q. What will happen if an excpetion that is thrown may causes a whole load of objects to go out of scope?
View solution
Q. What operation can be performed by destructor?
View solution
Q. What is the main purpose of the constructor?
View solution
Q. Why is it expensive to use objects for exception?
View solution
Q. Which alternative can replace the throw statement?
View solution
Q. What are the disadvantages if use return keyword to return error codes?
View solution
Q. What is most suitable for returning the logical errors in the program?
View solution
Q. What is the use of RAII in c++ programing?
View solution
Q. How many levels are there in exception safety?
View solution
Q. Pick out the correct statement for error handling alternatives.
View solution
Q. What will happen when an exception is not processed?
View solution
Q. Which header file is used to declare the standard exception?
View solution
Q. Where are standard exception classes grouped?
View solution
Q. How many types of standard exception are there in c++?
View solution
Q. Which of the following is best to include under try block?
View solution
Q. What are the perdefined exceptions in c++?
View solution
Q. A default catch block catches
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!