[英]Continue script execution after try/except exception with Python
来自其他脚本语言,我可能在这里遗漏了一些基本的东西。
引发异常时如何继续执行脚本的其余部分?
例子:
errMsg = None
try:
x = 1
y = x.non_existent_method()
except ValueError as e:
errMsg = str(e)
if errMsg:
print('Error')
else:
print('All good')
脚本只是失败了。 有没有办法继续其余的?
提前致谢
对不起,这个愚蠢的问题。 它应该是“异常”而不是“ValueError”
errMsg = None
try:
x = 1
y = x.non_existent_method()
except Exception as e:
errMsg = str(e)
if errMsg:
print('Error')
else:
print('All good')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.