Created
March 8, 2016 12:37
-
-
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
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
| 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