catching all exceptions

nospam at our.site nospam at our.site
Thu Feb 8 09:30:24 EST 2001


This message has been posted by:  Arne Mueller <a.mueller at REMOVE-THIS-TO-SENDicrf.icnet.uk>

Hi All,

I'm (still) using python 1.5.2 and I'd like to catch all exceptions in a
try block then find out what kind of exception excatly was risen and
save the output that would have been produced if I hadn't cought the
exception (or the stack-trace up to this position). Something like this:

try:
    do_something()
except (IOError, ...), value:
    this_exception = Exception_class
    ...
    write_Exception_to_database(this_exception, value)
    raise this_exception, value

The thing is that my program may raise all kinds of exceptions (not only
user defined exceptions), and I'd like to write the exception class (not
the Exceptions base class), the value, and the stack-trace up to this
point as one big string to a database before terminating the program.

currently I'm doing:

try:
  do_something()
except Exceptions, value:
  write_Exception_to_database('Python-Error: ' + repr(value))
  sys.exit(-1)  

with this I think I can catch all predefined exception classes, because
Exceptions is the base class for all other exceptions, but I realy want
to know which derived exception class was raised (and also the
stack-trace).

Is there (simple) way to do that in python (1.5.2)?

	thanks alot for help,

	Arne

-- 
Arne Mueller
Biomolecular Modelling Laboratory
Imperial Cancer Research Fund
44 Lincoln's Inn Fields
London WC2A 3PX, U.K.
phone : +44-(0)207 2693405      | fax :+44-(0)207-269-3534
email : a.mueller at icrf.icnet.uk | http://www.bmm.icnet.uk



More information about the Python-list mailing list