Exceptions: Logging TB and local variables?

allen.fowler allen.fowler at yahoo.com
Wed Oct 10 06:03:50 CEST 2007


Hi,

My code looks like this:

for item in bigset:
  self.__sub1(item)
  self.__sub2(item)
  self.__sub3(item)

# the subX functions, in turn, use various 3rd party modules.


Now, I would like to do this:

for item in bigset:
  try:
    self.__sub1(item)
    self.__sub2(item)
    self.__sub3(item)
  except StandardError:
    # Log error and continue to next item in set.
    log_error_to_file()


In the error log, I would like to record various local variables that
existed in subX at the time the Exception was thrown... (even though
the actuall exception may have been thrown from deep inside some 3rd
party module that subX called)

How can I do this?

Thank you,
Allen




More information about the Python-list mailing list