I am have a question pertaining to handling specific errors in arcpy 3.7. I want to capture the specific ERROR 000466: <value> does not match the schema of target <value>. The following code narrows it down to the arcpy.ExecuteError, but I cannot find a graceful method to further identify the error as ERROR 000466. The sys.exc_info()[1] returns the entire error value but I would just like the error number without having to parse the string.
try:
my code here...
except arcpy.ExecuteError:
e = sys.exc_info()[1]
print(e)
except:
handle of other errors
Solved! Go to Solution.
I can't easily recreate the ExecutionError exception but one thing I would try is to see what you get with the exception's 'args' property, which will give you the arguments passed in by the ESRI code when the exception was created.
try:
my code here...
except arcpy.ExecuteError as ex:
print (str(ex.args)) # Maybe the specific error code is one of the args ??????
e = sys.exc_info()[1]
print(e)
except:
handle of other errors
Seems like arcpy.ExecuteError has only two public attributes: args and with_traceback(). You probably won't get around parsing the string.
try:
arcpy.management.Append(fc_wrong_schema, target_fc)
except arcpy.ExecuteError as e:
if "ERROR 000466" in e.args[0]:
# handle
print("DELETE FEATURE CLASS")
else:
# handle or raise
raise
except:
# handle or raise
pass
I can't easily recreate the ExecutionError exception but one thing I would try is to see what you get with the exception's 'args' property, which will give you the arguments passed in by the ESRI code when the exception was created.
try:
my code here...
except arcpy.ExecuteError as ex:
print (str(ex.args)) # Maybe the specific error code is one of the args ??????
e = sys.exc_info()[1]
print(e)
except:
handle of other errors
ex.args only contains a single element which is the full error description. Path names removed and replaced with "<value>".
ERROR 000466: <value> does not match the schema of target <value>
Failed to execute (Append).
As noted previously, I can parse this string to get the error number, but I can remember older versions of Python having an errno value. Ultimately, I want to delete the feature class when this error occurs and create a new version with the modified schema.
Seems like arcpy.ExecuteError has only two public attributes: args and with_traceback(). You probably won't get around parsing the string.
try:
arcpy.management.Append(fc_wrong_schema, target_fc)
except arcpy.ExecuteError as e:
if "ERROR 000466" in e.args[0]:
# handle
print("DELETE FEATURE CLASS")
else:
# handle or raise
raise
except:
# handle or raise
pass
Thanks for the reply. I just wanted to make sure I was not missing something obvious.