What happens when an exception is thrown in C++ and a matching catch block is found?

Options

  • A. The exception is handled by the matching catch block.
  • B. The program always ignores the exception.
  • C. The compiler restarts the program automatically.
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. The exception is handled by the matching catch block.

Detailed Explanation

Answer: (A) The exception is handled by the matching catch block.

When an exception is thrown, C++ searches for a suitable catch handler.

If a matching handler is found, control is transferred to that catch block and the exception can be handled there.

This mechanism separates the normal program logic from exception-handling logic.