Python Exception Notes
Python Exception Notes
*************************
or error
* syntax error
while true:
True ==>
* logical error
/
//
ex:2
c=0
a=int(input("enter a"))
b=int(input("enter b"))
try:
c=a/b
except:
print('error occured, may be zero divide')
print(c)
ex:3
a=int(input("enter a"))
b=int(input("enter b"))
try:
c=a/b
print(c)
except ZeroDivisionError:
print("zero division error")
c=a/b
print(c)
except ZeroDivisionError:
print("zero division error")
except ValueError:
print("check the input")
ex:5 (finally)
try:
a=int(input("enter a"))
b=int(input("enter b"))
c=a/b
print(c)
except ZeroDivisionError:
print("zero division error")
except ValueError:
print("check the input")
finally:
print(" thank you")
Raising Exception
****************
The raise statement allows the programmer to force a specific exception to occur.
ex:
try:
raise NameError("Hi there") # Raise Error
except NameError:
print ("An exception")