Difficulty: Medium
Correct Answer: C is printed before exiting with an error message.
Explanation:
Introduction / Context:
This tests your understanding of Java's Throwable hierarchy and catch matching. Error is not a subtype of Exception; therefore catch(Exception) does not handle an Error. However, finally still executes.
Given Data / Assumptions:
Concept / Approach:
Error represents serious problems that a reasonable application should not try to catch. Since Error is not an Exception, the catch(Exception) block will not handle it. The JVM unwinds the stack after finally runs.
Step-by-Step Solution:
Verification / Alternative check:
Change the catch to catch(Throwable) or catch(Error) to handle it; then "C" would still print, and the program could continue to print "D".
Why Other Options Are Wrong:
They imply catch(Exception) would handle Error or that finally does not run, both incorrect.
Common Pitfalls:
Assuming Exception catches everything under Throwable; forgetting the special place of Error and its subclasses.
Final Answer:
C is printed before exiting with an error message.
Discussion & Comments