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


Picture showing the output of Exception handling in python


Picture showing the output of Exception handling in python



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



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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250