C++ Programming Multiple Choice Questions - Exception Handling
This section focuses on the "Exception Handling" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which keyword is used to handle the expection?
View Answer
2. Which is used to throw a exception?
View Answer
3. Which exception is thrown by dynamic_cast?
View Answer
4. How do define the user-defined exceptions?
View Answer
5. We can prevent a function from throwing any exceptions.
View Answer
6. In nested try block, if inner catch handler gets executed, then __________?
View Answer
7. Return type of uncaught_exception() is ___________.
View Answer
8. Which of the following statements are true about Catch handler?
i) It must be placed immediately after try block T.
ii) It can have multiple parameters.
iii) There must be only one catch handler for every try block.
iv) There can be multiple catch handler for a try block T.
v) Generic catch handler can be placed anywhere after try block.
View Answer
9. If inner catch handler is not able to handle the exception then__________ .
View Answer
10. Which type of program is recommended to include in try block?
View Answer
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
21. Which statement is used to catch all types of exceptions?
View Answer
22. How to handle error in the destructor?
View Answer
23. What kind of exceptions are available in c++?
View Answer
24. Which of the following is true about exception handling in C++?
i) There is a standard exception class like Exception class in Java.
ii) All exceptions are unchecked in C++, i.e., compiler doesn't check if the exceptions are caught or not.
iii) In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.
View Answer
25. What is the basic of grouping standard exception classes,in c++?
View Answer
26. What is a count of standard exception?
View Answer
27. What should be included in try block in c++ programming language?
View Answer
28. How many standard exception exist in c++?
View Answer
29. Catch-all handlers uses which operators in c++?
View Answer
30. Uncaught exception will call which function?
View Answer
31. Which operator in c++ programming language , is used by catch-all handler?
View Answer
32. How to handle exception in constructor, in c++?
View Answer
33. How many parameter does the throw expression has, in c++?
View Answer
Also check :
Discussion