Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q13 of Q15
Python - Custom Exceptions
What will be the output of this code?
class MyError(Exception):
    pass

try:
    raise MyError('Oops!')
except MyError as e:
    print(e)
AMyError
BException
COops!
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand raising and catching custom exception

    The code raises MyError with message 'Oops!'.
  2. Step 2: What does print(e) show?

    Printing the exception variable e shows the message passed during raise.
  3. Final Answer:

    Oops! -> Option C
  4. Quick Check:

    Exception message prints when caught and printed [OK]
Quick Trick: Print exception object to see its message [OK]
Common Mistakes:
MISTAKES
  • Printing exception class name instead of message
  • Expecting no output because of exception
  • Confusing exception type with message

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes