You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyodbc
Hi,
I'm having trouble trapping exceptions returned from pyodbc cursor
execute calls. Maybe I am referencing the wrong exceptions ???? I have
googled around quite a bit and it seems my code should
work...Basically, I have tried trapping all the error codes, but none
of them work. I'm connected to MS SQL database.
conn = pyodbc.connect( 'SelectWillFail * from [Test]')
cur = conn.cursor()
try:
cur.execute ( 'some garbage')
except pyodbc.Error:
print 'Error exc'
except pyodbc.DataError:
print 'Data Error'
except pyodbc.DatabaseError:
print 'Database error'
..... catch rest of the errors......
except:
print 'Why did I get here!!!!!'
I always end up with 'Why did I get here!!!!!!!'
Any ideas ?????? I MUST be doing something wrong !!!!!! Help !!!!!!
Thanks in advance for your time,
Gary
SRage
unread,
Mar 2, 2009, 4:59:17 PM3/2/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyodbc
What exception are you getting?
E.g., change your last except clause to something like:
except:
print sys.exc_info()
yee...@gmail.com
unread,
Mar 2, 2009, 5:30:52 PM3/2/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyodbc
Here is the sys.exc_info()..............................
(<type 'instance'>, <pyodbc.ProgrammingError instance at 0xb7d0e32c>,
<traceback object at 0xb7d0fb1c>)
So, I see pyodbc.ProgrammingError, but I can't seem to trap it.
Thanks
mkleehammer
unread,
Mar 10, 2009, 11:49:21 AM3/10/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyodbc
This turns out to be related to the 'finally pops a bad exception'
issue you see discussed on other threads.
There is also an issue open for this which I will try to resolve as
soon as possible. Maybe this week. (I've been swamped for 3 months
now. There is light at the end of the tunnel, though.)
http://code.google.com/p/pyodbc/issues/detail?id=40
mkleehammer
unread,
Mar 18, 2009, 3:39:51 PM3/18/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyodbc
Fixed in f98eac65ce01ccac56711293ade0c30d4c4fa39d, which will be in
2.1.5 as soon as
I release it.
Apparently *neither* solution was correct by itself -- you have to
sometimes use
in_class and sometimes the type. Python 2.6 has
PyExceptionInstance_Class exactly
for this. Since we also build for 2.4 I simply did the same thing the
macro does.