examples/exceptions/show_exception_type.py
from __future__ import print_function

def read_file(f):
    print("before " + f)
    try:
        with open(f, 'r') as fh:
            number = int(fh.readline())
            print(30 / number)
    except Exception as e:
        print("  {}".format(e))
        print("  {}".format(type(e)))
        print("  there was a problem in " + f)
    print("after  " + f)

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

for f in files:
    read_file(f)

# before one.txt
# 30
# after  one.txt
# before zero.txt
#   integer division or modulo by zero
#   <type 'exceptions.ZeroDivisionError'>
#   there was a problem in zero.txt
# after  zero.txt
# before two.txt
#   [Errno 2] No such file or directory: 'two.txt'
#   <type 'exceptions.IOError'>
#   there was a problem in two.txt
# after  two.txt
# before three.txt
# 10
# after  three.txt