0% found this document useful (0 votes)
13 views2 pages

Exceptional

Exception handling in python

Uploaded by

sdhinesh2909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Exceptional

Exception handling in python

Uploaded by

sdhinesh2909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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