poros
10/4/2015 - 2:04 PM

Complete exception handling

Complete exception handling

try:
    f = open(filename, 'r')
except IOError as e:
    print 'cannot open ', filename
    print "I/O error({0}): {1}".format(e.errno, e.strerror)
except:
    log.exception("Unexpected error")
    # print "Unexpected error:", sys.exc_info()[0]
    raise
else:
    print 'read', len(f.readlines()), 'lines'
finally:
    print "executing finally clause"