Exception handling in Python
http://docs.python.org/library/imaplib.html states that:
Exception raised on any errors. The reason for the exception is passed to the constructor as a string.
exception IMAP4.error
What does "exception is passed to the constructor as a string" mean? What would the co开发者_运维知识库de look like that can print the reason.
Just use print str(exception)
.
You can specify the reason when constructing the exception yourself, and put it into a variable when catching the exception.
try:
raise imaplib.IMAP4.error('Some exception')
except imaplib.IMAP4.error, error:
print error
精彩评论