[Zope-DB] SQL exception handling questions

Dieter Maurer dieter@handshake.de
Mon, 17 Mar 2003 22:10:09 +0100

Luis Mariano Luporini wrote at 2003-3-17 12:57 -0300:
 >        Now the questions:
 >        1) I've read about try/except and StandarError.
 >            if I use something like:
 >                try:
 >                        some statement
 >                except StandardError, e:
 >                        print e
 >        I got a whole string containing the sql executed an a description 
 > of the error. So what is e really?

An "Exception" instance, more precisely, a "Psycopg" exception.

 > Can I get an error number, 

No, as PostgreSQL does not report error numbers.

 > description and more information out of e? If not how can i do it?

you can convert it into a string (with the built in function
"str") and get something quite readable.

 >        2) Trying to specialize the exception treated I changed 
 > StandardError for IntegrityError/DatabaseError but in both cases i got:
 >        *Error Type: NameError*
 >         Error Value: global name 'DatabaseError/IntegrityError' is not 
 > defined*

You must import them.

 >        Then i added to the script "import psycopg", with the same 
 > results and finally tried "import psycopg.Error" and got
 >        *Error Type: ImportError*
 >         Error Value: import of "psycopg.Error" is unauthorized

Read the "README" of Python Scripts. It tells you how
to allow import.