mxODBC and exceptions

Mikael Lexén lexen at stop.spam.telia.com
Thu Sep 13 03:31:46 EDT 2001


Paul Boddie wrote:

> Mikael Lexén <lexen at telia.com> wrote in message news:<3B9F14DD.3B9CC835 at telia.com>...
> > Hi
> >
> > I'm using the mxODBC module and I have problem getting the exception
> > clause to work.
> > I do the following:
> >
> > import mx.ODBC
> >
> > <code>
> >
> > try:
> >   c.executedirect(Sql)
> >
> > #except mxODBC.IntegrityError:
>
> Did you mean mx.ODBC.IntegrityError here?
>
> > #except IntegrityError:
> > except:
> >    print "Unexpected error:", sys.exc_info()[0]
> >    raise
>
> [...]
>
> > I have tried different exception clause as you can see but it doesn't
> > work. What am I doing wrong?
>
> You might want to import mx.ODBC in the interactive interpreter (for
> convenience) and then inspect the package's different namespaces,
> using statements such as...
>
>   dir(mx.ODBC)
>
> I'm sure it's there somewhere!
>
> Paul

Thanks for pointing me in the right direction. The exception clause should be

except mx.ODBC.Windows.IntegrityError:

I was fooled by

except:
    print "Unexpected error:", sys.exc_info()[0]

that sad

Unexpected error: mxODBC.IntegrityError
                          ~~~~~~~~~~~~~~

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.

Are there any function that can give me the real "name" of the exception (just curious)?

--
/Mikael




More information about the Python-list mailing list