with arcpy.da.SearchCursor(fc, "ST_ID", "1=2") as cursor: arcpy.AddMessage("In the With") try: test = cursor.next() arcpy.AddError("ERROR: There is more than one ...") sys.exit(1) except StopIteration: arcpy.AddMessage("All is good, there's one and only one ...") pass
Solved! Go to Solution.
numRows = int(arcpy.GetCount_management(fc).getOutput(0)) if numRows == 1: arcpy.AddMessage("All is good, there's one and only one ...") else: arcpy.AddError("All is not good: {0} rows found".format(numRows))
with arcpy.da.SearchCursor(fc, "ST_ID") as cursor: arcpy.AddMessage("In the With") try: test = cursor.next() arcpy.AddMessage("Got one.") test = cursor.next() # try get a second row except StopIteration: arcpy.AddError("ERROR: There is more than one ...") sys.exit(1) except: arcpy.AddError("Something else happened!")