[Tutor] catching any exception?
Lance E Sloan
lsloan@umich.edu
Wed Nov 13 12:00:04 2002
I'm using the DCOracle 1.1.1.1 module with a Python 2.0 CGI. Sometimes
when I try to execute a SQL statement, an exception will be raised. It may
be because I wrote bad SQL or it may be that a relationship was going to be
broken, etc. I would like to have the same exception raised, but I also
want to have the SQL statement printed. So I tried this section of code:
try:
cursor.execute(sql)
except Exception, thisException:
raise Exception(thisException, sql)
This didn't work. Apparently although "Exception" is the parent of all
exceptions, it is not an exception itself, so this never matched. Is there
something I can put in place of "Exception" in the "except" clause that
will match all kinds of exceptions, so that I can get the kind of exception
that was raised in my variable "thisException"?
For now I'm using this:
try:
cursor.execute(sql)
except:
raise Exception(sql)
Which means I'm losing information about what kind of exception was raised.
--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting. Specializing in Python & Perl CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"