Tuesday, August 23, 2011

Ignoring Errors, Sometimes You Need To...

Say you need to write a multiprocessing script to perform a long running process and it's going to run on Windows XP or 7.  Sometime it can throw random IO errors, like data does not exists with ArcPy functions.

To compensate for that, you can embed try/except statements to ignore specific errors within your program.

For example:

try:
    try:
        fsock = open(r"c:\temp\test2.sde", "r")
    except IOError:
        pass
    print 'its all good'
except:
    print 'OH NO SOME ERROR HAS HAPPENED!'
finally:
    print 'see no errors, my script is awesome!'


The code will just ignore and IOErrors that occur during that section of code. I do not recommend using this all the time, but there are times were odd OS issues can prevent a multiprocessing task from completing correctly, at least in my experience.

Enjoy