Bird
0
0

Identify the problem in this code snippet:

medium📝 Debug Q7 of 15
Python - Custom Exceptions
Identify the problem in this code snippet:
class MyError(Exception):
    pass

try:
    raise MyError
except MyError as e:
    print(e())
ASyntaxError due to missing parentheses in raise
BNo error, prints empty string
CNameError because MyError is not defined
De() causes TypeError because exception instance is not callable
Step-by-Step Solution
Solution:
  1. Step 1: Understand exception instance usage

    Exception instances are objects, not functions, so calling them like e() causes an error.
  2. Step 2: Identify error type

    Calling e() raises a TypeError because the instance is not callable.
  3. Final Answer:

    e() causes TypeError because exception instance is not callable -> Option D
  4. Quick Check:

    Exception instances are not callable [OK]
Quick Trick: Do not call exception instances like functions [OK]
Common Mistakes:
  • Calling exception instance as a function
  • Missing parentheses in raise statement
  • Assuming exception instance is callable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes