Question: What is exception? What is difference between Syntax Error and Exceptions? Give an example of division by zero exception using try catch statement. See the

What is exception? What is difference between Syntax Error and Exceptions?
Give an example of division by zero exception using try catch statement. See the
codes block (i) and (ii) and compare the output :
(i) try:
a =[1,2,3]
print (a[3])
except LookupError:
print ("Index out of bound error.")
else:
print ("Success")
(ii)
a =[1,2,3]
try: print ("Second element =%d"%(a[1]))
print ("Fourth element =%d"%(a[3]))
except:
print ("An error occurred")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!