Python Errors and Exceptions

/ Published in: Python
Save to your folder(s)

Copy this code and paste it in your HTML
  1. import sys
  2. try:
  3. f = open('myfile.txt')
  4. s = f.readline()
  5. i = int(s.strip())
  6. except IOError, (errno, strerror):
  7. print "I/O error(%s): %s" % (errno, strerror)
  8. except ValueError:
  9. print "Could not convert data to an integer."
  10. except:
  11. print "Unexpected error:", sys.exc_info()[0]
  12. raise


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.