我想弄清楚如果我不知道什么是异常,我将如何打印异常。我该怎么做?
try:
some_command
except:
print *full_exception_trace*
答案 0 :(得分:6)
try:
something()
except SomeException as e:
something_else(e)
您可能会发现traceback
有用。
答案 1 :(得分:3)
def exception(self)
try:
Something.objects.all()
except Exception, err:
print err.message #(if you want)
#raise err
raise # The 'raise' statement with no arguments inside an error
# handler tells Python to re-raise the exception with the
# original traceback intact
err.message会告诉你异常的原因
答案 2 :(得分:1)
traceback
模块的print_exc()
功能似乎就是您想要的。 Docs