I am experienced programmer, and no stranger to exceptions, try blocks, and exception classes in programming languages. But I continue to be proven wrong when it comes to exceptions being thrown during arcpy cursor operations.
I am working with a file geodatabase and whenever an exception is thrown during a cursor operation (whether Search, Insert, or Update), when I go back to my map, my layers don't draw; when I go back to my attribute table, it is empty and shows an error message sometimes. Here is pseudo-code for the pattern I use. Any feedback and explanations would be helpful. Note that this pattern works just fine when no exceptions are thrown.
def sampleFunc(fc, flds, query, data):
with arcpy.da.UpdateCursor(fc, flds, query) as uCursor:
try:
for row in uCursor:
# some business logic here which works for most rows but
# may throw an unhandled exception on a particular row.
row[4] = aFunction(row[3])
uCursor.updateRow(row)
finally:
del uCursor
In order to see my map and attribute tables again, I simply close down the project (with or without saving) and open it up again.