OA. free
Free
Micron Core Computer Science Core Computer Science Medium

QUESTION 27 --- What happens when a member function throws an exception?

Micron technical mcq question, verified with a worked answer. Free to practise - no sign-up.


What happens when a member function throws an exception?

Choose one option.
Show answer & explanation
Answer: B. Control is transferred to the catch block following the try block.

When a member function throws an exception, the normal execution flow is interrupted and control is transferred to the nearest enclosing catch block that handles that exception type. If no catch block is found, the exception propagates up the call stack. Option A is incorrect because the program doesn't necessarily terminate—it depends on exception handling. Option C is vague and misleading. Option D is incorrect because control doesn't simply return; it jumps to the catch handler.

Step-by-step Derivation:
Exception handling in C++ follows the try-catch-throw mechanism: (1) A try block contains code that might throw an exception. (2) If an exception is thrown, execution of the try block stops immediately. (3) The runtime searches for a matching catch block. (4) If a matching catch is found, control transfers there and the catch block executes. (5) If no catch is found, the exception propagates to the caller. The correct answer is B because this is the defined behavior of exception handling.