相关疑难解决方法(0)

使用回溯记录异常

如何记录我的Python错误?

try:
    do_something()
except:
    # How can I log my exception here, complete with its traceback?
Run Code Online (Sandbox Code Playgroud)

python error-handling logging exception

123
推荐指数
6
解决办法
10万
查看次数

python 中出现错误时如何运行函数

我有一个名为 的函数onError()。当它运行时,它会打印"There was an error"

我希望这个函数在发生错误时运行,例如,如果我 raise NameError,该函数就会运行。

这是我的代码

def onError():
    print("There was an error")

raise NameError
Run Code Online (Sandbox Code Playgroud)

我知道 try 和 except 存在,但我想要一种没有它们的方法。

python

2
推荐指数
1
解决办法
417
查看次数

标签 统计

python ×2

error-handling ×1

exception ×1

logging ×1