python中打印空白异常

2024-04-26 09:05:28 发布

您现在位置:Python中文网/ 问答频道 /正文

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

try:
    some_command
except:
    print *full_exception_trace*

Tags: exceptiontracesomecommandfullprinttryexcept
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

在错误消息会告诉你例外的原因

Like the tutorial says.

try:
  something()
except SomeException as e:
  something_else(e)

您可能会发现^{}很有用。在

traceback模块的print_exc()函数似乎就是您想要的。Docs

相关问题 更多 >