簡體   English   中英

在python中打印空白異常

[英]Print blank exception in python

我想弄清楚如果我一開始不知道異常是什么,該如何打印異常。 我該怎么辦?

try:
    some_command
except:
    print *full_exception_trace*

就像本教程說的那樣。

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

您可能會發現traceback很有用。

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將為您提供異常原因

traceback模塊的print_exc()函數似乎正是您想要的。 文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM