where can I find good reference document on python exception
It doesn't seem easy to find good reference document that details all python exceptions.
For example, whenever I got IOError exception, it has a different message format but I could not find any good reference:
IOError: ('http protocol 开发者_JAVA技巧error', 0, 'got a bad status line', None)
or
IOError: [Errno socket error] [Errno 110] Connection timed out
Built-in Exceptions are documented, here's IOException. Check errno
documentation for symbol definition, errno.errorcode
is a dict containing a mapping between error code/symbols.
import errno
errno.errorcode[numeric_code]
I guess that you are looking for errno:
try:
open('file_dont_exist')
except IOError as ex:
if ex.errno == errno.ENOENT:
print "no such file or directory"
精彩评论