【发布时间】:2021-09-21 00:32:17
【问题描述】:
发生错误后是否可以继续执行代码?
假设我有一个名为 app.py 的代码,其中包含以下代码 -
def call(temp):
call=temp+1
t=fast+1
if temp==11:
c=22/3
else:
c=1
return 5
这里没有定义fast,但我仍然希望代码在发生此错误后仍能执行。
我查看了互联网并找到了 pass 技巧,但它不适用于我的情况?
import app
def test_call():
try:
app.call(11)
except Exception:
pass
test_call()
在我的例子中,代码只执行到fast 行。有什么办法可以继续执行吗?
感谢和抱歉我的英语不好。
【问题讨论】:
-
你能举一个更现实的例子吗?如果
t没有被赋值,那么让代码继续运行有什么意义?
标签: python python-3.x exception try-catch