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")




Picture showing the output of Exception handling in python

Click to Enlarge

Picture showing the output of Exception handling in python

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 4, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250