Recently I was running a geometry simplification script I've been using for about two years. I had never had a problem with it, but suddenly I started ERROR 999999: Error executing function. This error is basically ArcGIS saying "I have no idea what happened". Man I was bummmin...no lines numbers...no idea why after so long I had a problem. Was it the data? Well, yes...it turned out the Shape field was named 'Shape_' instead of 'Shape'.
To find the error, I wrapped the script inside a try/except block and used two functions in my helper class:
def reportGPErrors(self, geoprocessor):
reports any geoprocessing related errors
gpmsgs = geoprocessor.GetMessage(0)
gpmsgs += geoprocessor.GetMessages(2)
def reportSysErrors(self, geoprocessor):
reports python system related errors
tb = sys.exc_info()
tbinfo = traceback.format_tb(tb)
pymsg = "PYTHON ERRORS:\nTraceback Info:\n"
pymsg += tbinfo + "\n"
pymsg += "Error Info:\n" + str(sys.exc_type) + ": "
pymsg += str(sys.exc_value) + "\n"
Both of the functions take a geoprocessor, which gives the ability to print to both the python console and the ArcGIS message window.
To implement these function in geoprocessing scripts, simply import helpers class, and place a call to these function in the try/except block:
from helpers import Helpers
oHelpers = Helpers()
gp = oHelpers.createGeoprocessor()