LearnFrenzy
Sign in Take a free test

Exception Handling · Predict the Output · Question 7

Raising and catching a custom exception Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

What is the output of the following Python program?

main.py
class InsufficientFunds(Exception):
    pass

try:
    raise InsufficientFunds("need 500 more")
except Exception as e:
    print(type(e).__name__, "-", e, isinstance(e, Exception))
  • A Exception - need 500 more True
  • B InsufficientFunds - InsufficientFunds False
  • C need 500 more
  • D InsufficientFunds - need 500 more True Correct
Correct Answer: Option D

except Exception catches the subclass; the object keeps its own class name and message.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links