假设我有一大堆代码,每当我遇到异常时我都会忽略它并继续下一行。这在python中可能吗?我想要像 -
这样的东西try:
#some code here
#see an exception, ignore, continue to next line
#more code
#any more code , ignore and march on through rest of block
except:
pass
答案 0 :(得分:0)
是的,你可以这样做,try-except必须围绕每一行,一旦行抛出异常,它将转到异常语句然后转到下一行。你最好打印/记录异常行。
for line in inputs:
try:
# your code here
except Exception as e:
# log your exception here