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

Thomas Wouters thomas at python.org
Tue Jan 23 18:07:40 CET 2007


On 1/23/07, Steven Bethard <steven.bethard at gmail.com> wrote:
>
> On 1/23/07, Thomas Wouters <thomas at python.org> wrote:
> >
> > On 1/22/07, Mark Hammond <mhammond at skippinet.com.au> wrote:
> > > > 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.
> >
> > I agree, and believe sys.exc_info() should just stay. There's also the
> case
> > of try/finally and fetching any raised exception there. (In fact,
> doesn't
> > the 'with' statement do something similar?)
>
> Sorry, for those of us following along at home ;-) could someone
> explain why we couldn't just introduce a ``sys.get_exception()`` or
> something like that which would then make the exception (and therefore
> the traceback) available?


We could, of course, but what's the point? To rename the existing 'exc_info'
into 'get_exception' and some attribute-retrieval? I'm all for cleanup and
not looking back, but that's quite a lot of gratuitous breakage, to little
point. I don't consider it 'weird' or 'bad' or 'a wart' or 'a hysterical
raisin' that sys.exc_info() returns a tuple of three things.

-- 
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070123/76df9383/attachment.htm 


More information about the Python-3000 mailing list