C++ MCQs (multiple choice questions) focuses on “Exceptions That Are Not Errors”. One shall practice these MCQs to improve their C++ programming skills needed for various interviews (campus interviews, walk in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our multiple choice questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.
C++ multiple choice questions on “Exceptions That Are Not Errors” along with answers, explanations and/or solutions:
Q 1. Which is used to handle the exceptions in c++?
A. catch handler
B. exception handler
C. handler
D. throw
Show Answer
B. exception handlerExplanation
Exception handler is used to handle the exceptions in c++.
Q 2. Which type of program is recommended to include in try block?
A. static memory allocation
B. dynamic memory allocation
C. const reference
D. pointer
Show Answer
B. dynamic memory allocationExplanation
While during dynamic memory allocation, Your system may not have sufficient resources to handle it, So it is better to use it inside the try block.
Q 3. Which statement is used to catch all types of exceptions?
A. catch()
B. catch(Test t)
C. catch(…)
D. catch(Test)
Show Answer
C. catch(…)Explanation
This catch statement will catch all types of exceptions that arises in the program.Q 4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int x = -1;
try
{
if (x < 0)
{
throw x;
}
else
{
cout<<x;
}
}
catch (int x )
{
cout << “Exception occurred: Thrown value is ” << x << endl;
}
return 0;
}
A. -1
B. 0
C. Exception occurred: Thrown value is -1
D. Error
Show Answer
C. Exception occurred: Thrown value is -1Explanation
As the given value is -1 and according to the condition, We are arising an exception. Output: $ g++ etae.cpp $ a.out Exception occurred: Thrown value is -1Q 5. What will be the output of the following C++ code?
#include <iostream>
#include <typeinfo>
using namespace std;
class Polymorphic {virtual void Member(){}};
int main ()
{
try
{
Polymorphic * pb = 0;
typeid(*pb);
}
catch (exception& e)
{
cerr << “exception caught: ” << e.what() << endl;
}
return 0;
}
A. exception caught: std::bad_typeid
B. exception caught: std::bad_alloc
C. exception caught: std::bad_cast
D. exception caught: std::bad_id
Show Answer
A. exception caught: std::bad_typeidExplanation
In this program, We used a bad type id for the polymorphic operator, So it is arising an bad_typeid exception. Output: $ g++ etae.cpp $ a.out exception caught: std::bad_typeid
Q 6. What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
void myunexpected ()
{
cout << “unexpected handler called\n”;
throw;
}
void myfunction () throw (int,bad_exception)
{
throw ‘x’;
}
int main (void)
{
set_unexpected (myunexpected);
try
{
myfunction();
}
catch (int)
{
cout << “caught int\n”;
}
catch (bad_exception be)
{
cout << “caught bad_exception\n”;
}
catch (…)
{
cout << “caught other exception \n”;
}
return 0;
}
A. unexpected handler called
B. caught bad_exception
C. caught other exception
D. both unexpected handler called & caught bad_exception
Show Answer
D. both unexpected handler called & caught bad_exceptionExplanation
In this program, We are calling set_unexpected and myfunction, So it is printing the output as the given. Output: $ g++ etae.cpp $ a.out unexpected handler called caught bad_exception
Q 7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int x = -1;
char *ptr;
ptr = new char[256];
try
{
if (x < 0)
{
throw x;
}
if (ptr == NULL)
{
throw ” ptr is NULL “;
}
}
catch (…)
{
cout << “Exception occurred: exiting “<< endl;
}
return 0;
}
A. -1
B. 1
C. ptr is NULL
D. exception occured: exiting
Show Answer
D. exception occured: exitingExplanation
catch(…) is used to catch all types of exceptions arising in the program. Output: $ g++ etea.cpp $ a.out Exception occured: exitingQ 8. What will be the output of the following C++ code?
#include <iostream>
#include <exception>
using namespace std;
void myunexpected ()
{
cout << “unexpected called\n”;
throw 0;
}
void myfunction () throw (int)
{
throw ‘x’;
}
int main ()
{
set_unexpected (myunexpected);
try
{
myfunction();
}
catch (int)
{
cout << “caught int\n”;
}
catch (…)
{
cout << “caught other exception\n”;
}
return 0;
}
A. caught other exception
B. caught int
C. unexpected called
D. both caught int & unexpected called
Show Answer
D. both caught int & unexpected calledExplanation
As we are calling set_unexpected (myunexpected) function, this is printing as unexpected called and because of operator compliance it is arising an exception. Output: $ g++ etea.cpp $ a.out unexpected called caught intQ 9. How to handle error in the destructor?
A. throwing
B. terminate
C. both throwing & terminate
D. try
Show Answer
B. terminateExplanation
It will not throw an exception from the destructor but it will the process by using terminate() function.Q 10. What kind of exceptions are available in c++?
A. handled
B. unhandled
C. static
D. dynamic
Show Answer
B. unhandledExplanation
unhandled kind of exceptions are available in c++.Q 11. Which keyword is used to signal that a specific condition (even if not an error) has occurred?
A. catch
B. throw
C. signal
D. goto
Show Answer
B. throwQ 12. Can a C++ exception be used as a way to exit deeply nested loops?
A. No, it’s strictly for errors.
B. Yes, though it is often considered poor style.
C. No, the compiler will throw a warning.
D. Yes, and it is the recommended way in the C++ Core Guidelines.
Show Answer
B. Yes, though it is often considered poor style.Q 13. When an exception is thrown for control flow, what happens to local objects in the current scope?
A. They are leaked.
B. They are kept in memory until the program ends.
C. Their destructors are called (Stack Unwinding).
D. They are moved to the heap.
Show Answer
C. Their destructors are called (Stack Unwinding).Q 14. In a search algorithm, throwing a “Found” exception to jump out of a recursive search is an example of:
A. An error state.
B. Using exceptions for non-local control flow.
C. Undefined behavior.
D. Memory corruption.
Show Answer
B. Using exceptions for non-local control flow.Q 15. Which of the following is a potential downside of using exceptions for non-error logic?
A. Increased binary size.
B. Performance overhead during the “throw” (RTTI and stack walking).
C. Code readability issues.
D. All of the above.
Answer: D
Show Answer
D. All of the above.Q 16. True or False: A catch(...) block can catch a custom “Status” object that does not inherit from std::exception.
A. True
B. False
Show Answer
A. True A (C++ allows throwing any type, including int or enum).Q 17. What happens if a “non-error” exception is thrown but never caught?
A. The program continues to the next line.
B. std::terminate is called.
C. The exception is automatically ignored.
D. The operating system catches it and prints “Success”.
Answer: B
Show Answer
B. std::terminate is called.Q 18. In the context of the std::optional or std::variant, why might exceptions be avoided for “not found” scenarios?
A. Because “not found” is an expected outcome, not an exceptional failure.
B. Exceptions are not allowed in templates.
C. Variants cannot hold exceptions.
D. Options are faster than catch blocks.
Show Answer
A. Because “not found” is an expected outcome, not an exceptional failure.Q 19. If a function is marked noexcept, what happens if you throw a “success signal” exception inside it?
A. The catch block outside the function handles it.
B. The function converts it to a return value.
C. std::terminate is called immediately.
D. The noexcept specifier is ignored.
Show Answer
C. std::terminate is called immediately.Q 20. Which design pattern is often an alternative to using exceptions for control flow?
A. Singleton Pattern
B. State Pattern or Return Codes
C. Factory Pattern
D. Observer Pattern
Show Answer
B. State Pattern or Return CodesQ 21. Why is using exceptions for normal logic considered “expensive”?
A. It requires a system call to the Kernel.
B. It prevents the compiler from using the CPU cache.
C. The “Happy Path” is fast, but the “Throw Path” involves complex stack walking.
D. It doubles the amount of RAM used.
Show Answer
C. The “Happy Path” is fast, but the “Throw Path” involves complex stack walking.Q 22. Can you throw a literal integer (e.g., throw 0;) to signal a specific state?
A. Yes.
B. No, only objects.
C. Only if the integer is negative.
D. Only in C, not C++.
Show Answer
A. Yes.Q 23. In “Exception-Safe” code, the “Strong Guarantee” means:
A. The code will never throw an exception.
B. If an exception occurs, the state is rolled back to the original.
C. The program will terminate safely.
D. No memory is leaked, but the state might change.
Show Answer
B. If an exception occurs, the state is rolled back to the original.Q 24. Which header defines the standard exception classes?
A. <error>
B. <iostream>
C. <stdexcept>
D. <exception_handle>
Show Answer
C.Q 25. What is “Stack Unwinding”?
A. Increasing the stack size during an error.
B. The process of destroying local objects as the scope exits during an exception.
C. A method to optimize loops.
D. Removing the exception from the catch block.
Show Answer
B. The process of destroying local objects as the scope exits during an exception.Q 26. Is it possible to re-throw an exception using the throw; statement (with no arguments)?
A. No.
B. Yes, but only in the try block.
C. Yes, inside a catch block to pass it up the chain.
D. Only if the exception is an error.
Show Answer
C. Yes, inside a catch block to pass it up the chain.Q 27. Which mechanism is generally faster for frequent, expected conditions?
A. throw/catch
B. if/else with return codes
C. setjmp/longjmp
D. std::terminate
Show Answer
B. if/else with return codesQ 28. If you use an exception to return a value from a deep recursion, where is that value stored during the unwinding?
A. On the stack of the function that throws.
B. In a dedicated “exception storage” area managed by the runtime.
C. In the CPU registers.
D. In a global variable.
Show Answer
B. In a dedicated “exception storage” area managed by the runtime.Q 29.What is a “User-defined Exception”?
A. An exception provided by the C++ Standard Library.
B. A custom class or type created by the programmer to signal specific events.
C. An exception thrown by the Operating System.
D. A hardware interrupt.
Show Answer
B. A custom class or type created by the programmer to signal specific events.Q 30. When should you not use exceptions for control flow?
A. In high-performance loops where the “exception” occurs frequently.
B. When using libraries that are not exception-safe.
C. When the logic can be easily expressed with break or return.
D. All of the above.


Leave a Reply