[Python-3000] Exceptions internals and removing sys.exc_*

Mark Hammond mhammond at skippinet.com.au
Mon Jan 22 07:56:33 CET 2007


> Guido has mentioned [1] that since exceptions will be growing a
> __traceback__ attribute in Python 3, it should be possible to remove
> sys.exc_info().

sys.exc_info() is also useful for returning the exception itself, not only
the traceback.  The traceback and logger modules both take advantage of it
to avoid the pain of passing exception objects around.  eg:

  try:
   ...
  except Foo:
    logger.exception("something bad happened")

is better than what may otherwise be necessary:

  except Foo, f:
    logger.exception("something bad happened", exc_info=f)

It seems a reasonable use case to have code that knows it is dealing with
exceptions, but not always be directly in the exception handler.

Cheers,

Mark



More information about the Python-3000 mailing list