Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
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)
ANo output
BMyError
CException
DOops!
Step-by-Step Solution
Solution:
  1. Step 1: Understand the raise statement

    The code raises MyError with message 'Oops!'.
  2. Step 2: Check the except block output

    The except block catches MyError as e and prints e, which is the message 'Oops!'.
  3. Final Answer:

    Oops! -> Option D
  4. Quick Check:

    Exception message prints = A [OK]
Quick Trick: Exception message prints when caught and printed [OK]
Common Mistakes:
  • Printing exception class name instead of message
  • Expecting no output
  • Confusing exception type with message

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes