Bird
Raised Fist0

Identify the error in this custom exception definition:

medium📝 Debug Q14 of Q15
Python - Custom Exceptions
Identify the error in this custom exception definition:
class CustomError(Exception):
    def __init__(self, message):
        print(message)
AException cannot be extended
BClass name should be lowercase
Cprint() cannot be used in __init__
DMissing call to super().__init__(message) in __init__
Step-by-Step Solution
Solution:
  1. Step 1: Check __init__ method in custom exception

    Custom exceptions should call the parent Exception __init__ to set the message properly.
  2. Step 2: Why call super().__init__(message)?

    This ensures the message is stored and accessible like normal exceptions.
  3. Final Answer:

    Missing call to super().__init__(message) in __init__ -> Option D
  4. Quick Check:

    Always call super().__init__ in custom exception init [OK]
Quick Trick: Call super().__init__ to set message in custom exceptions [OK]
Common Mistakes:
MISTAKES
  • Forgetting super().__init__ call
  • Thinking print replaces message storage
  • Believing class names must be lowercase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes