Error Handling: Try Exception

810
1
05-20-2013 01:04 PM
PeterWilson
Occasional Contributor III
I've developed a model within ModelBuilder that utilizes a large number of tools from various toolboxes as well as python scripts. I'm pretty new to Python as well as Programming. The model that I've developed is calculating the catchment characteristics for very large railway alignments in the excess of 1000 km alignments. If any of the tools within my model fail, it means rerunning the model from scratch. Now most of the errors that I receive is not syntax or incorrect datatypes, it more to do with the particular feature within the Feature Class being processed.

I wanted to find out if its possible to execute a tool and if the tool has a problem processing a particular feature within  a feature class will through an exception, report the feature that it has a problem with, but at least will move to the next feature within the feature class and continue processing.

I can then going through the feature that are causing the tool to through an exception to see why and run these features separately.

Any suggestions will be appreciated.

Regards
Tags (2)
0 Kudos
1 Reply
ColinConstance
New Contributor III

I wanted to find out if its possible to execute a tool and if the tool has a problem processing a particular feature within a feature class will through an exception, report the feature that it has a problem with, but at least will move to the next feature within the feature class and continue processing.



Ok so from this I take you want to do 2 things:
1. Loop through each feature and report problems if they occur, and
2. Continue processing all the remaining features.

You can narrow you exception reporting by doing the following:

try:
# place your code here for looping through each feature
except Exception, e:
    print "feature error: %s" % e
sys.exc_clear()


You may want to consider writing out a text file to store these feature errors.
The last line should allow the script to continue and is preferable to 'pass'

Anyway without seeing you code it is difficult to provide a generic solution so you probably want to test this on a small dataset first. Hope it helps.
0 Kudos