Skip to content

Instantly share code, notes, and snippets.

@thigm85
Created March 8, 2016 12:37
Show Gist options
  • Save thigm85/7dd82cb7d824d03e2e02 to your computer and use it in GitHub Desktop.
Save thigm85/7dd82cb7d824d03e2e02 to your computer and use it in GitHub Desktop.
Example of using a except clause wout type name. Reference: https://docs.python.org/2/tutorial/errors.html#handling-exceptions
import sys
try:
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
except ValueError:
print "Could not convert data to an integer."
except:
print "Unexpected error:", sys.exc_info()[0]
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment