Posted By

deepdown on 11/28/08


Tagged

python exception catch try


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

navi4all


Python Errors and Exceptions


 / Published in: Python
 

URL: http://www.python.org/doc/2.5.2/tut/node10.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  

You need to login to post a comment.