catching all exceptions

Siggy Brentrup bsb at winnegan.de
Thu Feb 8 10:13:39 EST 2001


nospam at our.site writes:


[...]

> 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)?

import traceback, cStringIO

f = cStringIO.StringIO
traceback.print_exc(None, f)

write_to_database(f.getvalue())

HTH
  Siggy





More information about the Python-list mailing list