Bird
0
0

What happens if an exception is raised inside the try block but there is no matching except block?

easy📝 Conceptual Q1 of 15
Python - Advanced Exception Handling
What happens if an exception is raised inside the try block but there is no matching except block?
AThe program crashes immediately without running <code>finally</code>.
BThe <code>except</code> block runs even if it doesn't match the exception.
CThe exception is ignored and the program continues normally.
DThe <code>finally</code> block still runs before the program crashes.
Step-by-Step Solution
Solution:
  1. Step 1: Understand exception handling flow

    If an exception occurs and no matching except block is found, Python looks for a handler up the call stack.
  2. Step 2: Role of finally block

    The finally block always runs, even if the exception is not caught locally.
  3. Final Answer:

    The finally block still runs before the program crashes. -> Option D
  4. Quick Check:

    finally block runs even if exception uncaught [OK]
Quick Trick: finally always runs, even if exception is uncaught [OK]
Common Mistakes:
  • Thinking finally block is skipped if exception is uncaught
  • Assuming program crashes before finally runs
  • Believing except runs without matching exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes