I'm working on some code for a toolbar I made using Python-addin that makes buildings. Part of the code that does this makes a Temporary table view. If my code attempts to make that table view again when it already exists, this error is thrown:
Traceback (most recent call last): File "filepath", line error happens on, in onClick '') File "otherfilepath", line I didn't code, in MakeTableView raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000725: Table Name: Dataset editViewStormBill already exists. Failed to execute (MakeTableView).
I've already made changes in my code to ensure that this error isn't thrown every time a building is drawn. This error is only thrown right now if the user takes a specific action that shows they don't really understand how the toolbar works. What I would like to do is catch the error with an exception that prints out a few lines explaining what the user did wrong and then pass over that part of the code so the rest of the code can attempt to run. I've done this before, but I don't know what to call the error in the try except statement. Here is the bit I'm struggling with:
if button2.isTableView == False: try: tableView = arcpy.MakeTableView_management(fc, "editView" + str(button2.i), "",workspace, '') arcpy.ChangeVersion_management((tableView),"TRANSACTIONAL", button2.currentVersion, '') button2.isTableView = True except ???:#What goes here? pass
So far I have tried putting ExecuteError where the questions marks are and nothing happens. What do I put after except; what part of the error tells me what to write for my exception in python?
I'm not overwriting output because that approach would have my code make the tableView every time this button is pressed which would make the toolbar slower and less useful.
If you need to reproduce this error in order to explain how to read error messages then do this:
try: tableView = arcpy.MakeTableView_management(fc, "editView", "",workspace, '') tableView = arcpy.MakeTableView_management(fc, "editView", "",workspace, '') arcpy.ChangeVersion_management((tableView),"TRANSACTIONAL", button2.currentVersion, '') button2.isTableView = True except :#What goes here? pass