How to Define As Many Exception Blocks As You Want in Python


In this example we will show how to define as many exception blocks as you want in Python.

Source Code

try:
    x = int('a')
except ValueError:
    print('String is invalid literal for int() with base 10.')
except:
    print('Other errors occurred!')

Output:

String is invalid literal for int() with base 10.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments