1

My code is as follows:

Essentially, I have one table in my database that is not able to convert into my FGDB. When I run on command line, I am able to get an error message of:

WARNING: Failed to convert Database Connections\DB.sde\Tablexxx. ERROR 999999: Error executing function.

Failed to execute (CopyRows).

But i am not able to print/write this error message to console (via print statement) or to a log file (via log.write). It seems that in my code, the except statements are not even being reached, even though an error is occuring?

closed as off-topic by PolyGeo Aug 11 at 20:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Your indentation for the second and third lines of code that you have presented is astray. I think you should print(tables) as a new first line. You have a tag for file geodatabase but seem to be using an enterprise geodatabase. – PolyGeo Jul 23 at 20:57
  • arcpy.AddError only functions with an ArcGIS script tool or Python toolbox tool. Is this a stand-alone script? – Emil Brundage Jul 23 at 22:25
  • 2
    print does not work within the ArcGIS platform. You want arcpy.AddMessage or its siblings, arcpy.AddWarning, arcpy.AddError. Just for grins, the messages object in Python toolbox uses messages.addMessage (lowercase a in add) and messages.addWarningMessage and messages.addErrorMessage (gotta stay on your toes) – Vince Jul 24 at 0:40
  • This, gis.stackexchange.com/a/160436/28687, may help. This is about piping your stream to be handled by right medium, I think. – fatih_dur Jul 24 at 1:18
  • I’m not clear why you’ve deleted your code from this coding question. What precisely did you run from the “command line” and by that do you mean the Python window of ArcMap or something else? – PolyGeo Aug 11 at 20:37
1

I'd just use except Exception as e:

>>> import arcpy
>>> try:
    arcpy.Buffer_analysis ("fdgfd", "dfgdg", "dsfsdfsd")
except Exception as e:
    print e


Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset fdgfd does not exist or is not supported
Failed to execute (Buffer).

>>> 
  • I tried this as well but the error message still does not show up – GISProdigy Jul 23 at 23:37
1

You are using print in one statement and arcpy.AddError() in another. The command line won't print errors from AddError() and the ArcGIS console won't print from print.

To be able to print the error both within the ArcGIS console and the command line you may want to use both print and AddError() from within your except statements:

except arcpy.ExecuteError:
    arcpy.AddError(arcpy.GetMessages(2))
    print(arcpy.GetMessages(2))

except:
    e = sys.exc_info()[1]
    arcpy.AddError(e.args[0])
    print(e.args[0])

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