开发者

Exception handling in Python

http://docs.python.org/library/imaplib.html states that:

exception IMAP4.error

Exception raised on any errors. The reason for the exception is passed to the constructor as a string.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜