Generic error handling
Jörg Baumann
joerg.baumann at stud.informatik.uni-erlangen.de
Sun Jan 13 06:43:01 EST 2002
Grzegorz Dostatni wrote:
> a) include some info for traceback to show
Your code is probably executed with exec. Wrap that in try: except: and
catch every exception. Add the information (where the code you _exec()ed_
came form.) and rethrow the exception.
Or use the filename argument of the builtin compile()
> b) catch the errors in a general way (no matter where they're execuded
> from) at an application level?
> I am looking for something what Tkinter
> does. How did they manage to get their own window to appear instead of
> dumping text to console??
I didn't use Tkinter, but I guess it is similar to Tcl/Tk error handling.
As most GUIs Tk is event driven. So after initialization your code enters
the event loop and waits for events. When an event (e.g. button pressed)
arrives it must be handled. If the event handler returns without an error
we wait for the next event. If the handler throws an exception we catch it
and display it within an error window and just wait for the next event (and
hope it was nothing realy serious ;-).
If your application has no central event loop you won't find a single point
for error handling/recovery and application wide error handling besides
abortion will be difficult.
More information about the Python-list
mailing list