mxODBC and exceptions

M.-A. Lemburg mal at lemburg.com
Tue Sep 18 15:36:41 EDT 2001


Paul Boddie wrote:
> 
> Mikael Lexén <lexen at stop.spam.telia.com> wrote in message news:<3BA060E1.C5D7E407 at stop.spam.telia.com>...
> >
> > Thanks for pointing me in the right direction. The exception clause should be
> >
> > except mx.ODBC.Windows.IntegrityError:
> 
> That looks better, at least.

The next release will provide access to the exceptions as
connection or cursor attributes.
 
> > Why didn't I get the answer mx.ODBC.Windows.IntegrityError? sys.exc_info()[0]
> > gives me the class instance and that name is obviously not the same as the
> > exception.
> 
> That's probably a question for Marc-André Lemburg, really. I would
> expect that the methods which generate the exceptions' visual
> representations are still giving names consistent with the old package
> structure as opposed to the newer package structure. However, this is
> just speculation.

This is due to the way that exceptions display themselves and
hard to fix. mxODBC consists of a large number of subpackages
each of which has its own set of these exceptions. I'll check
whether I can include some extra information in the exception
name to make finding them easier.
 
> > Are there any function that can give me the real "name" of the exception
> > (just curious)?
> 
> I don't know, but looking at the DB-API specification [1], I would
> think that you would find the exceptions under the module that you are
> importing. This made me think somewhat, because to write code portable
> across different modules, one would ideally use "neutral" names for
> things like exceptions; this would be rather like Java's java.sql
> package which provides interfaces that actual implementations support.
> (One doesn't need to catch com.sybase.jconnect.SomeException, or
> whatever.)
> 
> However, I suppose that a similar effect can be achieved by assigning
> any given implementation module to a "neutral" variable. For example:
> 
>   dbmodule = mx.ODBC.Windows
>   connection = dbmodule.connect(...)
>   ...
>   except dbmodule.IntegrityError, exc:
>     ...
> 
> Actually, there are a few more things with the DB-API that have come
> to light in various forums recently. Perhaps the DB-SIG mailing list
> should be reinvigorated...

Right. This exception thing is one particular nit I have with the 
DB API -- it makes writing cross-platform code more difficult than
it should be.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/





More information about the Python-list mailing list