Articles → Python → Exception Handling In Python
Exception Handling In Python
Syntax
try:
Code to be executed
except:
Executed when an exception occurs
Example
number = input("Please enter the number:")
number = int(number)
try:
print("Result is 10/number=", 10 / number)
except:
print("Error")
Output
Catching An Error Of A Particular Type
number = input("Please enter the number:")
number = int(number)
try:
print("Result is 10/number=", 10 / number)
except ZeroDivisionError:
print("Error")