How to Execute Specified Code Block in Python


In this example, we will learn how to execute the specified code block whether the try block raises an error in Python.

Source Code

try:
    x = int('a')
except:
    print('An exception occurred!')
finally:
    print('The exception is clear.')

Output:

An exception occurred!
The exception is clear.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement