Core Python
June 3, 2026 1 min read

Handling Exceptions in Python: Ensuring Program Robustness

HS
HEMANT SINGH
Technical Writer & Educator

Python exception is used to handle exception in a program, when we write a program it is good habit to write the code within try except block, using these blocks we can handle errors of program and error on program will not raise an error and rest of the code will run without any affect.

 

Example

try :
	a=10
	b=0
	c=a/b
	print(c)
except:
	print("There is an error")
finally:
	print("Program completed")

 

try

Write code or part of program here, in which exception may occur

 

except

This block will run when an exception occur

 

finally

This block will run always whatever an exception occur or not