Python: How to ignore an exception and proceed?

740    Asked by akashMishra in Python , Asked on Apr 9, 2021

I have a try...except block in my code and When an exception is throw. I really just want to continue with the code because in that case, everything is still able to run just fine. The problem is if you leave the except: block empty or with a #do nothing, it gives you a syntax error. I can't use continue because it's not in a loop. Is there a keyword I can use that tells the code to just keep going?

Answered by akash Mishra

If you want to ignore an exception in python (python ignore exception) and want to proceed further then you can use the following piece of code:-

try:
do_something()
except Exception:
pass

Your Answer

Interviews

Parent Categories