Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q13 of Q15
Python - Exception Handling Fundamentals
What will be the output of this code?
try:
    x = 5 / 0
except Exception:
    print("Error caught")
print("Done")
AZeroDivisionError\nDone
BError caught\nDone
CDone
DNo output, program crashes
Step-by-Step Solution
Solution:
  1. Step 1: Identify the error raised

    The code tries to divide 5 by 0, which raises a ZeroDivisionError, a subclass of Exception.
  2. Step 2: Check exception handling and output

    The except Exception block catches this error and prints "Error caught". Then the program continues and prints "Done".
  3. Final Answer:

    Error caught\nDone -> Option B
  4. Quick Check:

    ZeroDivisionError caught = prints error message and continues [OK]
Quick Trick: Generic except catches ZeroDivisionError and prints message [OK]
Common Mistakes:
MISTAKES
  • Expecting program to crash with error message
  • Thinking error message is printed automatically
  • Missing that 'Done' prints after exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes