It is currently Thu Sep 18, 2014 9:47 pm




Post new topic Reply to topic  [ 5 posts ] 
 Catching errors in Python 
Author Message
General
General

Joined: Fri Aug 03, 2007 11:39 am
Posts: 626
Location: Devon, England
Post Catching errors in Python
I'm trying to catch any possible errors arising from a SQL UPDATE (such as a duplicate key value) so that I can display a custom error message. I've tried the following code
Code:
try:
    runUpdateQuery(blah)
except:
    print "Error"
without success - even when the update fails the standard warning appears and 'Error' never gets printed in the console.

Is what I'm trying to do possible?

_________________
Al
DataCapture Ltd.

www.datacap.co.uk


Tue Jul 29, 2008 1:05 pm
Profile
Moderator
Moderator

Joined: Sun Apr 02, 2006 2:46 pm
Posts: 4056
Location: Sacramento, CA
Post Re: Catching errors in Python
Not currently, no. fpmi.db.runUpdateQuery catches errors internally and displays them. I've taken the liberty of moving this thread to the feature request forum.

_________________
Carl Gould
Co-Director, Software Engineering
Inductive Automation


Tue Jul 29, 2008 2:40 pm
Profile WWW
Moderator
Moderator

Joined: Sun Apr 02, 2006 2:46 pm
Posts: 4056
Location: Sacramento, CA
Post Re: Catching errors in Python
This has been changed in Ignition - all database errors can now be caught and handled via Python exception handling.

_________________
Carl Gould
Co-Director, Software Engineering
Inductive Automation


Thu Mar 04, 2010 10:32 am
Profile WWW
General
General

Joined: Fri Aug 03, 2007 11:39 am
Posts: 626
Location: Devon, England
Post Re: Catching errors in Python
That's great :thumb_left:

Just to prove users are never satisfied - is there any way you can trap a SQL error number from the database?

_________________
Al
DataCapture Ltd.

www.datacap.co.uk


Thu Mar 04, 2010 12:29 pm
Profile
Moderator
Moderator

Joined: Sun Apr 02, 2006 2:46 pm
Posts: 4056
Location: Sacramento, CA
Post Re: Catching errors in Python
You mean how to pull out details of the error that you've caught? You can catch the exception and learn about its cause like this:

Code:
import sys
from java.lang import Exception
try:
   system.db.runQuery("SELECT something FROM nothing")
   print 'Success!'
except Exception, errinfo:
   print 'Error running query: ', errinfo.cause.message

_________________
Carl Gould
Co-Director, Software Engineering
Inductive Automation


Thu Mar 04, 2010 1:53 pm
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: