Select to view content in your preferred language

Handle specific error in arcpy

1896
4
Jump to solution
01-09-2022 01:13 PM
LanceCole
MVP Regular Contributor

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

 

 

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
DonMorrison1
Frequent Contributor

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

 

 

View solution in original post

JohannesLindner
MVP Frequent Contributor

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

 


Have a great day!
Johannes

View solution in original post

4 Replies
DonMorrison1
Frequent Contributor

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

 

 

LanceCole
MVP Regular Contributor

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.  

JohannesLindner
MVP Frequent Contributor

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

 


Have a great day!
Johannes
LanceCole
MVP Regular Contributor

Thanks for the reply.  I just wanted to make sure I was not missing something obvious.

0 Kudos