Bird
Raised Fist0

Which statement about extending built-in exceptions is TRUE?

hard🧠 Conceptual Q10 of Q15
Python - Custom Exceptions
Which statement about extending built-in exceptions is TRUE?
ACustom exceptions must always override __str__ to work
BIf you don't call super().__init__, the exception message may be lost
CYou cannot add new attributes to custom exceptions
DCustom exceptions cannot be caught by except blocks
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each statement

    B is false because overriding __str__ is optional. C is false because you can add attributes. D is false because custom exceptions are caught normally.
  2. Step 2: Understand importance of super().__init__

    Not calling super().__init__ can cause the message to be missing from the exception instance.
  3. Final Answer:

    If you don't call super().__init__, the exception message may be lost -> Option B
  4. Quick Check:

    super().__init__ preserves exception message [OK]
Quick Trick: Call super().__init__ to keep message; __str__ override is optional [OK]
Common Mistakes:
MISTAKES
  • Thinking __str__ override is mandatory
  • Believing custom exceptions can't have attributes
  • Assuming custom exceptions can't be caught

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes