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 use the ‘except clause’ with No Exceptions in Python?

I have this code with except clause having no exceptions

try:
    print 'foo'+'qux'+ 7
except:
    print' There is error'

What is the utility of such code?


1 Answer
Rajendra Dharmkar

If we define except clause with no exceptions, it can handle all types of exceptions. However, neither it’s a good coding practice nor it is recommended.

If you run above code

try:
print 'foo'+'qux'+ 7
except:
print' There is error'

You get the output

There is error

This type of Python try-except block can handle all types of exceptions, but it’ll not be helpful to the programmer to find which type of exception occurred.

Advertisements

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