0

I am looping over a feature in Arcpy and doing several geoProcessing tasks on each feature/iteration.

The loop runs pretty well but crashes on some of the features. I dont really know why but its probably because of some geometry error or something weird.

enter image description here

I can see what files have been output along the way so I can simply restart the loop and bypass the bad feature.

If I could somehow detect a runtime error like above, I could restart the loop and bypass the bad features. Is there any way to fire a function on a Runtime Error event?

2
  • Are you accessing data off a server? I am wondering if the failure is due to a .loc file.
    – Aaron
    Commented Sep 2, 2014 at 22:30
  • No - All the data is local
    – jotamon
    Commented Sep 2, 2014 at 22:32

1 Answer 1

1

I would recommend using a try/except statement. For example:

for fc in fclist:
    try:
        yourFunction(fc)
    except:
        # Do something, possibly fix geometry
        print there was a problem with %s...moving on" % fc
        continue

You can also get more specific and handle only ExecuteErrors using except arcpy.ExecuteError::

More details:

Error handling with Python

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.