处理任意异常,打印默认异常消息 [英] Handle Arbitrary Exception, Print Default Exception Message
问题描述
,除了
块。 但是,当我这样做时,它除了
的所有异常,并继续与程序,我从来没有得到看到异常消息,我需要调试。
有没有办法除了
任何异常并且能够打印除
块之外的异常消息。
pre> 尝试:
#stuff
除了例外为e:
打印e
traceback
模块提供了从异常对象提取更多信息的各种功能( e
,以上)。
I have a program, a part of which executes a loop. During the execution of this loop, there are exceptions. Obviously, I would like my program to run without errors, but for the sake of progress, I would like the program to execute over the entire input and not stop when an exception is thrown. The easiest way to do this would be by implementing an except
block.
However, when I do this, it except
s all exceptions and continues with the program and I never get to see the exception message, which I need in order to debug.
Is there a way to except
any arbitrary exception and be able to print out the exception message in the except
block?
try:
#stuff
except Exception as e:
print e
The traceback
module provides various functions for extracting more information from the exception object (e
, above).
Source Errors and Exceptions
这篇关于处理任意异常,打印默认异常消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!