[Tutor] using sys.excepthook to handle unhandled exception (corrected and reposted)
Tony Cappellini
cappy2112 at gmail.com
Wed Aug 27 21:18:15 CEST 2008
I'm maintaining a large framework of python code where the original
authors left many assert statements.
When an unhandled exception occurs, the traceback is displayed on the
screen. Ideally, I don't want the users to see the tracebacks
from unhandled exceptions, but rather a short, useful message.
Users of a program shouldn't need to know anything about the language
the program was written in order to have an idea of what caused the
error.
I want to add an "unhandled exception handler" which logs the
tracebacks to a file, display a 1 line message as to where or why the
exception occurred.
Assigning my exception logger function to sys.excepthook is what I have in mind.
This exception logger will also display a message like this.
"An unhandled exception has occurred. This program will terminate.
Please email the "ErrorReport.txt" file to the developers"
Adding a function to log the tracebacks is easy, I'm more interested
in the side affects caused by assigning a function to sys.excepthook.
The framework I'm maintaining does NOT already use sys.excepthook.
That is a good beginning. ;-)
I would like to hear from the experiences of people "who have assigned
an exception handler function to sys.excepthook" as to how they
approached
this problem. More specifically, what issues they encountered, if any.
Thanks
More information about the Tutor
mailing list