Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q6 of 15
Python - Custom Exceptions
Find the error in this code snippet:
class MyException:
    pass

raise MyException('Oops')
ANo error, code runs fine
Braise keyword is misspelled
CMyException must inherit from Exception
DMyException cannot be raised
Step-by-Step Solution
Solution:
  1. Step 1: Check class definition

    MyException is defined without inheriting from Exception.
  2. Step 2: Understand raising exceptions

    Only classes inheriting from Exception can be raised as exceptions.
  3. Final Answer:

    MyException must inherit from Exception -> Option C
  4. Quick Check:

    Custom exceptions must inherit Exception to be raised [OK]
Quick Trick: Custom exceptions must inherit Exception to be raised [OK]
Common Mistakes:
  • Not inheriting from Exception
  • Misspelling raise
  • Assuming any class can be raised

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes