Function Overloading in C++
15 questions · 12 min · Medium
Test your knowledge of exception handling in C++ with 15 questions covering try, throw, catch, standard exceptions, multiple catch blocks, nested exceptions, and exception handling best practices.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. try, catch, throw
C++ uses try to define a block where exceptions may occur, throw to signal an exception, and catch to handle it.
B. throw
The throw keyword is used to signal an exception and transfer control to a matching catch handler.
A. try
Code that may generate an exception is placed inside a try block.
B. catch
A catch block specifies how to handle an exception thrown from a corresponding try block.
B. try { } catch(...) { }
A C++ try block must be followed by one or more catch handlers. The ellipsis in catch(...) can catch an exception of any type.
C. It can catch an exception of any type
A catch-all handler written as catch(...) can match exceptions regardless of their type.
C. The exception propagates and may result in program termination if uncaught
If an exception is not handled by a matching handler, it propagates up the call stack. If it remains uncaught, std::terminate() is ultimately called.
A. std::out_of_range
std::out_of_range is a standard exception type used to indicate that an argument or index is outside an acceptable range.
A. <exception>
The <exception> header provides std::exception and related exception-handling facilities.
C. what()
The what() member function of std::exception returns a null-terminated character sequence describing the exception.
B. To handle different types of exceptions separately
Multiple catch blocks allow a program to provide different handling logic for different exception types.
C. catch(const std::exception& e)
Catching a standard exception by const reference avoids unnecessary copying and can handle derived exception types through polymorphism.
A. The matching catch handler is searched for and normal execution of the try block stops
When an exception is thrown, control leaves the point of the throw and the runtime searches for a suitable catch handler.
A. std::invalid_argument
std::invalid_argument is a standard exception type used when a function receives an invalid argument.
B. It separates error-handling logic from normal program flow
Exception handling allows programs to separate exceptional error-handling code from the normal execution path, making error management more structured.