infobleep

How do I handle my own exceptions and get the excetion to run another prodcure?

Discussion created by infobleep on Sep 23, 2011
Latest reply on Sep 27, 2011 by stacyrendall
Hi there

I'm attempting to run a script in Python 2.6 referencing ArcGIS 10. I got the script to run but then I decided to use the try and except method and handle multiple exceptions.

However as soon as I started doing this I'm getting the following error:
except EXCEPTION:
NameError: global name 'EXCEPTION' is not defined
I think I need to define a class but I'm not sure how that would relate to then running an additional procedure. The idea of the programme is to create a backup of 3 feature classes and if errors occur, pass them to the error exception procedure. This then prints an error message and calls the procedure to restart the map services.

The section of code is as follows:

  print "\n5. Now renameing " + TABLE_OWNER + SDE_FC_CURRENT + " to " + TABLE_OWNER + SDE_FC_BACKUP + " providing no lock exists"
  try:
    try:
      if arcpy.Exists(TABLE_OWNER + SDE_FC_CURRENT) ==1:
        arcpy.Rename_management (TABLE_OWNER + SDE_FC_CURRENT,
                                 TABLE_OWNER + SDE_FC_BACKUP)
      print "test " + EXCEPTION
    except EXCEPTION:
      if arcpy.TestSchemaLock(TABLE_OWNER + SDE_FC_CURRENT) ==0:
        EXCEPTION(LOCK_ERROR_TEXT, SDE_FC_CURRENT)
    except LOCK_ON_BACKUP:
      if arcpy.TestSchemaLock(TABLE_OWNER + SDE_FC_BACKUP) ==0:
        EXCEPTION(LOCK_ERROR_TEXT, SDE_FC_BACKUP)
  except UNKNOWN_ERROR2:
    if arcpy.Exists(TABLE_OWNER + SDE_FC_CURRENT) ==0:
      EXCEPTION(UNKNOWN_ERROR, SDE_FC_CURRENT + " and " + SDE_FC_BACKUP)
I hope that is enough code. I can supply more if required.

Kind regards

Tim

Outcomes