Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

'''

Exception: RuntimeError or Runtime anamolies is called


Exception
Handle : To prevent an exception from terminating
a program using the try and except statements
Raise : To signal an exception using the raise statement.
'''

################################
#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)
'''

#5. try .. except..else(To catch all exception)


'''
try:
a=int(input("Enter the value of a :"))
b=int(input("Enter the value of b :"))
c=a/b
except :
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")

################################

You might also like