[DB-SIG] DCOracle-1.3.0 try/except
M.-A. Lemburg
mal@lemburg.com
Fri, 04 Aug 2000 00:25:33 +0200
LD Landis wrote:
>
> Hi,
>
> Dumb question... How do I do a "meaningful" try/except for DCOracle
> such that I can look at the error that was returned? I had thought
> that something like:
>
> try:
> db = DCOracle.Connect("user/password@instance.world")
> except DCOracle, e:
> print "Error", e
>
> would work, but it doesn't... Also tried using the various errors
> that Python catches without success... Here's what I get:
>
> Python 1.5.2 (#1, Jul 21 2000, 14:17:35) [C] on aix4
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> importr DCOracle
> >>> db = DCOracle.Connect("user/password@bogus.world")
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> File "/opt/oracle/local/lib/python1.5/DCOracle/ocidb.py", line 76, in __init__
> sc=oci_8.Logon(u,p,s)
> OracleError: ('ORA-12154: TNS:could not resolve service name\012', 12154)
> >>> try:
> ... db = DCOracle.Connect("user/password@bogus.world")
> ... except OracleError:
> ... print "error caught"
> ...
> Traceback (innermost last):
> File "<stdin>", line 3, in ?
> AttributeError: OracleError
> >>> try:
> ... db = DCOracle.Connect("user/password@bogus.world")
> ... except DCOracle.OracleError:
> ... print "error caught"
> ...
> Traceback (innermost last):
> File "<stdin>", line 3, in ?
> AttributeError: OracleError
> >>> try:
> ... db = DCOracle.Connect("user/password@bogus.world")
> ... except DCOracle.error:
> ... print "caught"
> ...
> Traceback (innermost last):
> File "<stdin>", line 2, in ?
> File "/opt/oracle/local/lib/python1.5/DCOracle/ocidb.py", line 76, in __init__
> sc=oci_8.Logon(u,p,s)
> OracleError: ('ORA-12154: TNS:could not resolve service name\012', 12154)
> >>> try:
> ... db = DCOracle.Connect("user/password@bogus.world")
> ... except DCOracle.error, e:
> ... print "caught", e
> ...
> Traceback (innermost last):
> File "<stdin>", line 2, in ?
> File "/opt/oracle/local/lib/python1.5/DCOracle/ocidb.py", line 76, in __init__
> sc=oci_8.Logon(u,p,s)
> OracleError: ('ORA-12154: TNS:could not resolve service name\012', 12154)
> >>> print e
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> NameError: e
> >>> try:
> ... db = DCOracle.Connect("user/password@bogus.world")
> ... except:
> ... print "Gotcha Suckers!"
> ...
> Gotcha Suckers!
> >>> print DCOracle.error
> oci.error
> >>> print DCOracle.error
> 'oci.error'
> >>> DCOracle.error
> 'oci.error'
> >>> ^D
Looks like DCOracle still uses strings as error objects - bad
thing since these are deprecated.
This should print the definition location of the error
message, BTW:
>>> import sys
>>> try:
... 1/0
... except:
... print sys.exc_info()
...
(<class exceptions.ZeroDivisionError at 80a6e30>, <exceptions.ZeroDivisionError instance at 80f4fe0>, <traceback object at 80f4f90>)
>>>
>>> import exceptions
>>> exceptions.ZeroDivisionError
<class exceptions.ZeroDivisionError at 80a6e30>
sys.exc_info()[0] has the class object you want !
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/