继续例外,然后转到下一个声明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

是的,您可以以这种方式进行操作,必须在每行周围进行试验,一旦行引发异常,它将转到异常语句,然后转到下一行。您最好打印/记录异常行。

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

最新更新