Skip to content
QuiznExam

Exception Handling in C++ Quiz – 15 Questions with Answers

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.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which keywords are primarily used for exception handling in C++?

    • A. try, catch, throw
    • B. check, error, handle
    • C. error, catch, finally
    • D. try, error, finally
    Show answer

    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.

  2. 2. Which keyword is used to explicitly generate an exception in C++?

    • A. catch
    • B. throw
    • C. raise
    • D. exception
    Show answer

    B. throw

    The throw keyword is used to signal an exception and transfer control to a matching catch handler.

  3. 3. Which keyword is used to define a block of code that may generate an exception?

    • A. try
    • B. catch
    • C. throw
    • D. handle
    Show answer

    A. try

    Code that may generate an exception is placed inside a try block.

  4. 4. Which keyword is used to handle an exception in C++?

    • A. handle
    • B. catch
    • C. except
    • D. recover
    Show answer

    B. catch

    A catch block specifies how to handle an exception thrown from a corresponding try block.

  5. 5. Which syntax correctly represents a basic C++ exception handling structure?

    • A. try { } catch { }
    • B. try { } catch(...) { }
    • C. try() { } handle() { }
    • D. check { } catch { }
    Show answer

    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.

  6. 6. What does catch(...) mean in C++?

    • A. It catches only integer exceptions
    • B. It catches only standard exceptions
    • C. It can catch an exception of any type
    • D. It disables exception handling
    Show answer

    C. It can catch an exception of any type

    A catch-all handler written as catch(...) can match exceptions regardless of their type.

  7. 7. What happens if no matching catch handler is found for a thrown exception?

    • A. The exception is automatically ignored
    • B. The program continues from the throw statement
    • C. The exception propagates and may result in program termination if uncaught
    • D. The compiler automatically creates a catch block
    Show answer

    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.

  8. 8. Which standard exception is commonly used when an operation attempts to access an element outside the valid range?

    • A. std::out_of_range
    • B. std::overflow
    • C. std::range_error_only
    • D. std::invalid_index
    Show answer

    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.

  9. 9. Which header provides the standard exception classes such as std::exception?

    • A. <exception>
    • B. <errors>
    • C. <throw>
    • D. <catch>
    Show answer

    A. <exception>

    The <exception> header provides std::exception and related exception-handling facilities.

  10. 10. Which method of std::exception can be used to obtain a descriptive error message?

    • A. message()
    • B. error()
    • C. what()
    • D. description()
    Show answer

    C. what()

    The what() member function of std::exception returns a null-terminated character sequence describing the exception.

  11. 11. What is the purpose of having multiple catch blocks after a try block?

    • A. To execute all handlers for one exception
    • B. To handle different types of exceptions separately
    • C. To make the try block execute multiple times
    • D. To prevent exceptions from being thrown
    Show answer

    B. To handle different types of exceptions separately

    Multiple catch blocks allow a program to provide different handling logic for different exception types.

  12. 12. Which is generally the preferred way to catch a standard exception object?

    • A. catch(std::exception e)
    • B. catch(std::exception& e)
    • C. catch(const std::exception& e)
    • D. catch(exception e*)
    Show answer

    C. catch(const std::exception& e)

    Catching a standard exception by const reference avoids unnecessary copying and can handle derived exception types through polymorphism.

  13. 13. What happens when an exception is thrown inside a try block?

    • A. The matching catch handler is searched for and normal execution of the try block stops
    • B. All catch blocks execute automatically
    • C. The exception is always ignored
    • D. The program always continues with the next statement inside the try block
    Show answer

    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.

  14. 14. Which standard exception is commonly associated with invalid arguments passed to a function?

    • A. std::invalid_argument
    • B. std::wrong_argument
    • C. std::bad_argument
    • D. std::argument_error
    Show answer

    A. std::invalid_argument

    std::invalid_argument is a standard exception type used when a function receives an invalid argument.

  15. 15. What is the main benefit of exception handling in C++?

    • A. It eliminates all programming errors
    • B. It separates error-handling logic from normal program flow
    • C. It makes every program execute faster
    • D. It prevents functions from returning values
    Show answer

    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.