Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

Can anyone tell me how to handle exception in Python?

1 Answer

0 votes
by (119k points)

Exception Handling will have two blocks: try and except. Try block will have the statements that may encounter an exception. If there will be no exceptions after execution, except block will be skipped.

Here is an example of exception handling that throws an error if we try to do division between an integer and a string:

try:

    a=5

    b='0'

    print(a/b)

except:

    print('Some error occurred.')

print("Out of try except blocks.")

I recommend enrolling in this Python Course by Intelllipaat to learn Python.

You can watch this Exception Handling in Python:

Browse Categories

...