0

I have seen code which 'converts' exception objects to the error string using str() like this:

try:
  ...
except Exception, err:
  print str(err)

Does err contain some public 'interface' through which its error string is fetched? I want to have the same functionality for my custom exception class. One way i can think of doing is just define a global str() method for all my exception objects and then inside just return the error string using getter. Is that how I should do it?

1 Answer 1

3

Just define __str__ method for your exception class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.