-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
  • 4,754
  • 8
  • 41
  • 69

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
  • 27,283
  • 17
  • 68
  • 115