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)
AOops!
BMyError
CException
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the raise statement with message

    The code raises MyError with the message 'Oops!'.
  2. Step 2: Catch the exception and print its message

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

    Oops! -> Option A
  4. Quick Check:

    Exception message prints = Oops! [OK]
Quick Trick: Exception instance prints its message string [OK]
Common Mistakes:
  • Printing exception class name instead of message
  • Not catching the exception properly
  • Expecting no output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes