-1

Lets say I have a big block of code and whenever I hit an exception I want to ignore it and proceed to next line. Is that possible in python? I want something like-

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
Illusionist
  • 5,204
  • 11
  • 46
  • 76

1 Answers1

0

Yes, you can do it in this way, the try-except must around each line, once the line throws exception, it will go to the exception statement and then go to next line. You'd better print/log the exception line.

for line in inputs:
    try:
        # your code here
    except Exception as e:
        # log your exception here
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125