Bird
Raised Fist0

If a return statement is executed inside a try block, what happens to the finally block?

easy🧠 Conceptual Q2 of Q15
C Sharp (C#) - Exception Handling
If a return statement is executed inside a try block, what happens to the finally block?
AThe finally block executes before the method returns.
BThe finally block is skipped because return exits the method.
CThe finally block executes only if an exception occurs.
DThe program throws an error due to return inside try.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze return inside try block

    When return is called, the method prepares to exit.
  2. Step 2: finally block execution

    Before exiting, the finally block always runs, even after return.
  3. Final Answer:

    The finally block executes before the method returns. -> Option A
  4. Quick Check:

    finally runs even after return = A [OK]
Quick Trick: finally runs even if try returns early [OK]
Common Mistakes:
MISTAKES
  • Assuming return skips finally
  • Thinking finally runs only on exceptions
  • Believing return causes program error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes