Articles → Python → Exception handling in python

Exception handling in python






Syntax




try:
   Code to be executed
except:    
   Executed when exception occurs



Example




number = input("Please enter the number:")

number = int (number)


try:
    print ("Result is 10/number=",10/number)
except:
    print("Error")





Click to Enlarge


Click to Enlarge


Catching an error of particular type




number = input("Please enter the number:")

number = int (number)


try:
    print ("Result is 10/number=",10/number)
except ZeroDivisionError:
    print("Error")



Posted By  -  Karan Gupta
 
Posted On  -  Monday, March 04, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250