I have a script that creates a new feature using arcpy.GetParameterAsText
, but I'm having trouble creating an error message for incorrect user input. The input for a parcel # should be something like '1500300000029', but what if 'sdfjfh' is entered? As it stands no error is thrown and a empty feature is created. I've also tried inside PythonWin by assigning a bad entry for 'input' and it runs without error.
import arcpy
import sys
arcpy.env.overwriteOutput = True
try:
Parcels = "..path to data"
arcpy.env.workspace = "C:/Data_new/Temp/Default.gdb"
#input = arcpy.GetParameterAsText(0)
input = "dfdsgdg"
expression = "PARCEL_ID = " + "'" + str(input) + "'"
arcpy.MakeFeatureLayer_management(Parcels, "parcels_lyr")
arcpy.SelectLayerByAttribute_management("parcels_lyr", "NEW_SELECTION", expression)
arcpy.CopyFeatures_management("parcels_lyr", "output")
except:
print arcpy.GetMessages()
I've also tried
except StandardError, ErrDesc:
arcpy.AddWarning(input)
arcpy.AddWarning(ErrDesc)
except:
arcpy.AddWarning(input)
arcpy.AddWarning(ErrDesc)
What is the appropriate way to handle this?