Bird
0
0

Why is it generally discouraged to use a return statement inside a finally block?

hard📝 Conceptual Q10 of 15
Python - Advanced Exception Handling
Why is it generally discouraged to use a return statement inside a finally block?
ABecause it causes syntax errors.
BBecause finally block never executes if return is used.
CBecause it suppresses exceptions and previous returns.
DBecause it makes the except block run twice.
Step-by-Step Solution
Solution:
  1. Step 1: Understand finally block behavior

    finally always runs, even if return or exception occurs.
  2. Step 2: Effect of return in finally

    Return in finally suppresses any exception or return from try/except blocks.
  3. Final Answer:

    It suppresses exceptions and previous returns, hiding errors. -> Option C
  4. Quick Check:

    Return in finally hides exceptions and returns [OK]
Quick Trick: Return in finally hides exceptions and previous returns [OK]
Common Mistakes:
  • Thinking return in finally causes syntax errors
  • Believing finally skips if return used
  • Assuming except runs multiple times

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes