在python中打印空白异常

时间:2012-05-29 03:04:39

标签: python

我想弄清楚如果我不知道什么是异常,我将如何打印异常。我该怎么做?

try:
    some_command
except:
    print *full_exception_trace*

3 个答案:

答案 0 :(得分:6)

Like the tutorial says.

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