Bird
Raised Fist0

What will this code print?

medium📝 Predict Output Q5 of Q15
Python - Advanced Exception Handling
What will this code print?
try:
    raise RuntimeError('Something went wrong')
except RuntimeError as e:
    print(e)
AError caught
BSomething went wrong
CRuntimeError
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the raise and except block

    The code raises a RuntimeError with a message, then catches it as 'e'.
  2. Step 2: Print the error message

    Printing 'e' outputs the error message string.
  3. Final Answer:

    Something went wrong -> Option B
  4. Quick Check:

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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes