Professional Documents
Culture Documents
Exceptional
Exceptional
################################
#1.try...except
'''
try:
a=int(input("Enter the value of a :"))
b=int(input("Enter the value of b :"))
c=a/b
print(c)
except ZeroDivisionError:
print("Divide by Zero error:You tried to divide the value by zero")
print("End")
'''
'''
#2.try...except...else
try:
a=int(input("Enter the value of a :"))
b=int(input("Enter the value of b :"))
c=a/b
except ZeroDivisionError:
print("Divide by Zero error:You tried to divide the value by zero")
else:
print("No Exception raise")
print("c=",c)
'''
####################################
#3.try...multiple except (Multiple Except Block)
'''
try:
a=int(input("Enter the value of a :"))
b=int(input("Enter the value of b :"))
c=a/b
except ValueError:
print("ValueError : Entered wrong data")
except ZeroDivisionError:
print("Divide by Zero error:You tried to divide the value by zero")
else:
print("No Exception raise")
print("c=",c)
'''
'''
#4.try... with single Except(HandleMultiple Exceptions)
try:
a=int(input("Enter the value of a :"))
b=int(input("Enter the value of b :"))
c=a/b
except(ValueError,ZeroDivisionError):
print("Exception araises")
else:
print("No Exception raise")
print("c=",c)
'''
'''
#try ... finally(Finally and else may not comes together)
try:
file1=open("E:\python program\sample1.txt","r")
print(file1.read())
print("hello")
except IOError:
print("File mode error")
finally:
print(file1.closed)
#file1.close()
#print("File closed")
#print(file1.closed)
'''
#############################
try:
a=10
b=0
c=a/b
print(c)
except ZeroDivisionError:
print("divide by error")
finally:
print("end of program")
################################