Loading

Quipoin Menu

Learn • Practice • Grow

python / Custom Exceptions
mcq
Direction: Choose the correct option

Q1.

How do you create a custom exception in Python?
A. Define a class
B. Define a class that inherits from `Exception`
C. Use `raise Exception`
D. Use `except`
Direction: Choose the correct option

Q2.

What should you define in a custom exception class?
A. Both A and C
B. Define `__str__`
C. Only `pass`
D. You can define `__init__` to accept custom messages
Direction: Choose the correct option

Q3.

How do you raise a custom exception?
A. raise MyException('error')
B. raise MyException
C. throw MyException
D. raise new MyException
Direction: Choose the correct option

Q4.

Can a custom exception have additional attributes?
A. Yes, but only in Python 3.11+
B. Only message
C. No
D. Yes, by defining `__init__`
Direction: Choose the correct option

Q5.

What is the best practice for naming custom exceptions?
A. End with 'Error'
B. Start with 'Custom'
C. All caps
D. Any name
Direction: Choose the correct option

Q6.

If you inherit from `Exception`, where does the custom exception belong in the exception hierarchy?
A. At the top
B. Under `ArithmeticError`
C. Under `Exception`
D. Under `BaseException`
Direction: Choose the correct option

Q7.

How can you differentiate between multiple custom exceptions?
A. Use error codes
B. Use try-except with specific types
C. Use if-else
D. Use different exception classes
Direction: Choose the correct option

Q8.

What does `raise MyError() from e` do?
A. Raises two exceptions
C. Chains exceptions, showing the original cause
D. Raises MyError with e as argument
Direction: Choose the correct option

Q9.

Should custom exceptions be defined in a module?
A. Only in classes
B. No, only in __main__
C. Only if needed
D. Yes, to reuse across modules
Direction: Choose the correct option

Q10.

What is the base class for exceptions that represent program errors?
A. SystemError
B. RuntimeError
C. Exception
D. BaseException