C++ Programming MCQ - Exception Handling
11. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
try
{
throw 'b';
}
catch (int param)
{
cout << "Int Exception";
}
catch (...)
{
cout << "Default Exception";
}
cout << "After Exception";
return 0;
}
View Answer
12. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
try
{
throw 10;
}
catch (...)
{
cout << "Default Exceptionn";
}
catch (int param)
{
cout << "Int Exceptionn";
}
return 0;
}
View Answer
13. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int P = -1;
try {
cout << "Inside try";
if (P < 0)
{
throw P;
cout << "After throw";
}
}
catch (int P ) {
cout << "Exception Caught";
}
cout << "After catch";
return 0;
}
View Answer
14. What is the output of this program?
#include <iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Derived LFC;
try {
throw LFC;
}
catch(Base LFC) {
cout<<"Base Exception";
}
catch(Derived LFC) {
cout<<"Derived Exception";
}
return 0;
}
View Answer
15. Which of the following is true about the following program
#include <iostream>
using namespace std;
int main ()
{
try
{
throw 10;
}
catch (int LFC)
{
cout << "An exception occurred " << LFC << endl;
}
return 0;
}
View Answer
16. What will be the output of this program?
#include <iostream>
using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception";
}
} ex;
int main ()
{
try
{
throw ex;
}
catch (exception& LFC)
{
cout << LFC.what() << endl;
}
return 0;
}
View Answer
17. What will be the output of this program?
#include <iostream>
using namespace std;
int main ()
{
try
{
int* myarray = new int[1000];
cout << "Allocated";
}
catch (exception& LFC)
{
cout << "Standard exception: " << LFC.what() << endl;
}
return 0;
}
View Answer
18. What will be the output of the following program?
#include <iostream>
using namespace std;
int main( )
{
try
{
string strg1("Test");
string strg2("ing");
strg1.append(strg2, 4, 2);
cout << strg1 << endl;
}
catch (exception &LFC)
{
cout << "Caught: " << LFC.what() << endl;
cout << "Type: " << typeid(LFC).name() << endl;
};
return 0;
}
View Answer
19. Which illustrate predefined exceptions
View Answer
20. What is not called terminate() function in an constructor?
View Answer
Also check :