Created
October 4, 2015 14:04
-
-
Save poros/1a2f28dba06c76639804 to your computer and use it in GitHub Desktop.
Complete exception handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment