# Catching Database Errors

**URL:** <https://forum.inductiveautomation.com/t/catching-database-errors/1331>\
**Category:** Archived Topics\
**Created:** [October 13, 2009, 7:38pm UTC](https://forum.inductiveautomation.com/t/catching-database-errors/1331 "2009-10-13T19:38:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HandledException](https://avatars.discourse-cdn.com/v4/letter/h/b19c9b/32.png) [@HandledException](https://forum.inductiveautomation.com/u/HandledException)\
**Post date:** [October 13, 2009, 7:38pm UTC](https://forum.inductiveautomation.com/t/catching-database-errors/1331/1 "2009-10-13T19:38:45Z")

</div>

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… 😉

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

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [October 14, 2009, 4:11pm UTC](https://forum.inductiveautomation.com/t/catching-database-errors/1331/2 "2009-10-14T16:11:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HandledException](https://avatars.discourse-cdn.com/v4/letter/h/b19c9b/32.png) [@HandledException](https://forum.inductiveautomation.com/u/HandledException)\
**Post date:** [October 14, 2009, 6:02pm UTC](https://forum.inductiveautomation.com/t/catching-database-errors/1331/3 "2009-10-14T18:02:57Z")

</div>

> [@Carl.Gould](#):
>
> 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
