Q: handling exceptions

Karsten Weinert k.weinert at gmx.net
Tue Sep 17 12:27:21 EDT 2002


Hello,
being new to python, I have a question about handling exceptions. I
want to catch an exception which is raised from a module not written
by me, and display a messagebox with the message of the exception
rather than halting the program. The problem is: how can I access the
message string of the exception?
Here is an example:

import mx.ODBC.Windows
import win32api, win32con

conn=mx.ODBC.Windows.Connect("...")
curs=conn.cursor()
try:
  curs.execute("INSERT INTO test VALUES ('abc',1)"
except mx.ODBC.Windows.IntegrityError:
  # how can I set exceptionstr now?
  win32api.MessageBox(0, "Integrity Error", exceptionstr, win32con.MB
OK)
  pass

Any help appreciated,
Karsten.



More information about the Python-list mailing list