Advertisement
rfmonk

exceptions.py

Dec 24th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. # e.g. from docs.python.org/2/tutorial/errors.html
  4.  
  5. import sys
  6.  
  7. try:
  8.     f = open('myfile.txt')
  9.     s = f.readline()
  10.     i = int(s.strip())
  11. except IOError as e:
  12.     print "I/O error({0}): {1}".format(e.errno, e.strerror)
  13. except ValueError:
  14.     print "Could not convert data to an integer."
  15. except:
  16.     print "Unexpected error:" sys.exc_info()[0]
  17.     raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement