Bird
0
0

Which of the following is the correct syntax to define a custom exception class named DataError?

easy📝 Syntax Q3 of 15
Python - Custom Exceptions
Which of the following is the correct syntax to define a custom exception class named DataError?
Adef DataError(Exception):\n pass
Bclass DataError(Exception):\n pass
Cclass DataError():\n pass
Dexception DataError(Exception):\n pass
Step-by-Step Solution
Solution:
  1. Step 1: Recall class definition syntax

    Classes are defined with the keyword 'class' followed by the name and optional base class in parentheses.
  2. Step 2: Check each option

    class DataError(Exception):\n pass correctly uses 'class' and inherits from Exception. Others use wrong keywords or omit inheritance.
  3. Final Answer:

    class DataError(Exception):\n pass -> Option B
  4. Quick Check:

    Correct class syntax = class DataError(Exception):\n pass [OK]
Quick Trick: Use 'class' keyword and inherit from Exception [OK]
Common Mistakes:
  • Using 'def' instead of 'class'
  • Omitting inheritance from Exception
  • Using invalid keywords like 'exception'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes