Exceptions: Logging TB and local variables?
allen.fowler at yahoo.com
Thu Oct 11 08:53:50 CEST 2007
> Two possibilieies:
> You will need to determine ALL the exceptions that the 3rd party party modules
> can raise. If they are custom exceptions you will need to import them into your
> application from their modules.
> say that 3rd party modules raise TransientError, IOError, and ValueError
> exceptions. TransientError is a custom exception from module foo
> from foo import TransientError
> for item in bigset:
> except (TransientError, IOError, ValueError):
> # Log error and continue to next item in set.
> 2) Hook exception traceback handler
> def myTraceBackHandler(type, value,tb):
> global <variables I want to dump during traceback>
> # This function allows the user to redefine what happens if the program
> # aborts due to an uncaught exception.
> # This provides a way to get a "partial" session log if the program
> # aborts"as well as some information about what caused the program to
> # abort.
> import traceback
> # Get traceback lines
> tblines=traceback.format_exception(type, value,tb)
> # Write some lines to log
> # Always write the exceptions to screen
> Hope this helps.
This looks interesting...
What is myTraceBackHandler? Is it some sort of event handler? Can you
More information about the Python-list