Error Handling

System-related errors are typically translated into the following

  • OSError - General operating system error
  • IOError - I/O related system error

Cause of the error is contained in errno attribute of exception

  • Can use the errno module for symbolic error names

Example:

     import os, errno
     ...
     try:
          os.execlp("foo")
     except OSError,e:
          if e.errno == errno.ENOENT:
               print "Program not found. Sorry"
          elif e.errno == errno.ENOEXEC:
               print "Program not executable."
          else:
               # Some other kind of error
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 56
July 17, 2000, beazley@cs.uchicago.edu
>>>