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:
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.
Step 2: Understand importance of super().__init__
Not calling super().__init__ can cause the message to be missing from the exception instance.
Final Answer:
If you don't call super().__init__, the exception message may be lost -> Option B
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
Master "Custom Exceptions" in Python
9 interactive learning modes - each teaches the same concept differently