for loop try except python code example
Example 1: try catch python
try:
print("try to run this block")
except:
print("run this bock if there was error in earlier block")
Example 2: try for loop python
try:
with open('sample.txt','r') as file:
for line in file:
(some action here)
except IOError:
except IOError as (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)