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

URL: http://www.python.org/doc/2.5.2/tut/node10.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.