### Geoprocessing script traceback error info ### import os, sys, traceback def trace(): tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # script name + line number line = tbinfo.split(", ")[1] # Construct the pathname to this script. Get the pathname # to the folder containing the script using sys.path[0]. # Modify line below and replace 'myscript.py' with the name of # this script. filename = sys.path[0] + os.sep + "ScriptFileName.py" #<--- Insert filename # Get Python syntax error synerror = traceback.format_exc().splitlines()[-1] return line, filename, synerror ## Try-Except clause format: # try: # your code here # except arcpy.ExecuteError: # for msg in range(0, arcpy.GetMessageCount()): # if arcpy.GetSeverity(msg) == 2: # arcpy.AddReturnMessage(msg) # except: # line, filename, err = trace() # arcpy.AddError("Python error on " + line + " of " + filename) # arcpy.AddError(err) # print "Python error on " + line + " of " + filename # print err
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.