examples/exceptions/selective_exception_handling.py
from __future__ import print_function

def read_file(f):
    try:
        with open(f, 'r') as fh:
            number = int(fh.readline())
            print(30 / number)
    except IOError:
        print("Could not open file: {}".format(f))

files = 'one.txt', 'zero.txt', 'two.txt', 'three.txt'

for f in files:
    print("before " + f)
    try:
        read_file(f)
    except ZeroDivisionError:
        print("  there was a problem in {}".format(f))
    print("after  " + f)

# before one.txt
# 30
# after  one.txt
# before zero.txt
#   there was a problem in zero.txt
# after  zero.txt
# before two.txt
# Could not open file: two.txt
# after  two.txt
# before three.txt
# 10
# after  three.txt