开发者

Exception handling in Python

开发者 https://www.devze.com 2023-01-12 00:21 出处:网络
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.

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

精彩评论

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