Computer >> Computer tutorials >  >> Programming >> Python

How to ignore an exception and proceed in Python?


We can run a try-except block without handling the exception the following ways:

try:
1/0
except:
pass

and

try:
1/0
except Exception:
pass

In the first case, using bare except: is like using except BaseException:  which will also catch KeyboardInterrupt, SystemExit and errors like that, which are derived directly from exceptions.BaseException, not exceptions.Exception.

In second case, the things mentioned above won't be caught. The pass statement makes it possible to ignore the exceptions.