Overriding traceback print_exc()?
Ziga Seilnacht
ziga.seilnacht at gmail.com
Tue Oct 31 15:43:58 EST 2006
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)?
You can overwrite the sys.exepthook() with your own function:
import sys
from traceback import format_exception
def my_excepthook(exctype, value, traceback):
details = "".join(format_exception(exctype, value, traceback))
# now show the details in your dialog box
sys.excepthook = my_excepthook
See the documentation for details:
http://docs.python.org/lib/module-sys.html#l2h-5125
Hope this helps,
Ziga
More information about the Python-list
mailing list