继续异常并转到下一个语句python

时间:2016-12-15 15:59:16

标签: python

假设我有一大堆代码,每当我遇到异常时我都会忽略它并继续下一行。这在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

1 个答案:

答案 0 :(得分:0)

是的,你可以这样做,try-except必须围绕每一行,一旦行抛出异常,它将转到异常语句然后转到下一行。你最好打印/记录异常行。

for line in inputs:
    try:
        # your code here
    except Exception as e:
        # log your exception here