Catching Database Errors

Hi Everyone,

How would I go about catching the errors thrown by fpmi.db? I think I understand how exception handling works in python, but my except clause never seems to fire. I would like my script to be a little more user friendly and hide the scary sql error messages… :wink:

Here’s what I have been trying so far:

try : fpmi.db.runPrepStmt("INSERT INTO %s (TypeID, TypeName, TypeColor, TypeDesc) VALUES (NULL, ?, ?, ?)" % (types_table), [type_name, type_color, type_desc]) fpmi.gui.messageBox("Success!") except : fpmi.gui.messageBox("Error!")
I want to be able to catch duplicate violations, etc. Also, is there a list of the possible exceptions somewhere?

Thanks for the help.

–HandledException

You’ve stumbled upon a somewhat embarrassing inconsistency in the fpmi.db.* functions. Some of them throw a (catchable) Python exception when problems arise, but others simply display the error and then return -1.

These ones throw an exception:
fpmi.db.runQuery
fpmi.db.runScalarQuery

And these ones show the exception
fpmi.db.runUpdateQuery
fpmi.db.runUpdateQueryGetKey
fpmi.db.runPrepStmt

At the risk of sounding like a broken record: this has been resolved in the next major version.

No problem Carl. I'm just glad I can get some straight answers on this stuff. On top of that every single issue I have run into is currently being addressed, which is awesome!

Thanks for the info.

--HandledException