How to Handle an Exception in Python


In this example we will show how to handle an exception using the try statement in Python.

Source Code

try:
    x = int('a')
except:
    print('An exception occurred!')

Output:

An exception occurred!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments