Overriding traceback print_exc()?

draghuram at gmail.com draghuram at gmail.com
Tue Oct 31 21:46:31 CET 2006

I usually have a function like this:

def get_excinfo_str():
    """return exception stack trace as a string"""

    (exc_type, exc_value, exc_traceback) = sys.exc_info()
    formatted_excinfo = traceback.format_exception(exc_type, exc_value,
    excinfo_str = "".join(formatted_excinfo)

    del exc_type
    del exc_value
    del exc_traceback


I can then call it from within "except" and print it to a log file.


Bob Greschke wrote:
> I want to cause any traceback output from my applications to show up in one
> of my dialog boxes, instead of in the command or terminal window (between
> running on Solaris, Linux, OSX and Windows systems there might not be any
> command window or terminal window to show the traceback messages in).  Do I
> want to do something like override the print_exc (or format_exc?) method of
> traceback to get the text of the message and call my dialog box routine?  If
> that is right how do I do that (monkeying with classes is all still a grey
> area to me)?
> I kind of understand using the traceback module to alter the output of
> exceptions that I am looking for, but I'm after those pesky ones that should
> never happen. :)
> Thanks!
> Bob

More information about the Python-list mailing list