I find the traceback functionality very useful and I adapted the scripts examples from the suggested blog link below for ArcGISv10. I included a snippet of the modified working script.http://blogs.esri.com/dev/blogs/geoprocessing/archive/2008/12/01/tips-and-tricks-_2d00_-error-handli...I noticed in that the blog uses the "def trace():" inside (tip#4) or outside (tip#5) the try block? What is the logic for putting it inside vs. outside? # Import system module
from xml.etree import ElementTree
import arcpy, string, os
def trace():
import sys, traceback
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
line = tbinfo.split(", ")[1]
filename = sys.path[0] + os.sep + "test.py"
synerror = traceback.format_exc().splitlines()[-1]
return line, filename, synerror
if __name__ == '__main__':
try:
inShapeFile= arcpy.GetParameterAsText(0) #final edited polygon shapefile
inFile=arcpy.GetParameterAsText(1) #for R1 is .txt, for R2 is .xml
polList=str(arcpy.GetParameterAsText(2))#user select from drop list
# all the processing code goes here.....
except arcpy.ExecuteError:
#Return Geoprocessing tool specific errors
line, filename, err = trace()
arcpy.AddError("Geoprocessing error on " + line + " of " + filename + " :")
for msg in range(0, arcpy.GetMessageCount()):
if arcpy.GetSeverity(msg) == 2:
arcpy.AddReturnMessage(msg)
except:
#Gets non-tool errors
line, filename, err = trace()
arcpy.AddError("Python error on " + line + " of " + filename)
arcpy.AddError(err)