try:
something here
except:
print('the whatever error occurred.')
如何在我的except:
块中打印错误/异常?
#1楼
如果您要传递错误字符串,请参见以下来自错误和异常 (Python 2.6)的示例
>>> try:
... raise Exception('spam', 'eggs')
... except Exception as inst:
... print type(inst) # the exception instance
... print inst.args # arguments stored in .args
... print inst # __str__ allows args to printed directly
... x, y = inst # __getitem__ allows args to be unpacked directly
... print 'x =', x
... print 'y =', y
...
<type 'exceptions.Exception'>
('spam', 'eggs')
('spam', 'eggs')
x = spam
y = eggs