3

I am with ArcGIS 10.1. In my Python script, I need to catch arcgisscripting.ExecuteError and other general Python errors. When a arcgisscripting.ExecuteError is thrown, I also need to retrieve error details.

For example

try:
      # UploadServiceDefinition_server would throw a arcgisscripting.ExecuteError error if an error occurs
      arcpy.UploadServiceDefinition_server(sd, 'My Hosted Services', service, 
                                                 '', 'FROM_SERVICE_DEFINITION', 'EXISTING', 
                                                 'STARTED', 'OVERRIDE_DEFINITION', 'SHARE_ONLINE', 
                                                 'PUBLIC', 'SHARE_ORGANIZATION', '')

except arcgisscripting.ExecuteError:

except:
  general errors
finally:
  do other stuff
5

I suspect what you actually want to catch is an arcpy.ExecuteError (or have you imported arcgisscripting somewhere in your code?)

except arcpy.ExecuteError:
    print arcpy.GetMessages()
    # Handle the code somehow
except Exception:
    e = sys.exc_info()[1]
    print(e.args[0])
    arcpy.AddError(e.args[0])
finally:
  do other stuff

See also Error handling with Python

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.