Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to ignore an exception and proceed in Python?

When you just want to do run a try-except block without handling the exception; how do you do it in Python?


1 Answer
Rajendra Dharmkar

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.

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.