[Python-Dev] Traceback problem

Guido van Rossum guido@python.org
Tue, 25 Feb 2003 10:12:46 -0500


> > 1) Implement exeptions according to the documentation.
> >     Cleaning exceptions after they are handled is what
> >     most users would expect, last but not least since
> >     the documentation suggests it.
> 
> This is not a practical option -- while I don't think the current
> behavior is ideal, we have a great deal of code that relies on this
> behavior.  I'm sure that many other Python developers are in the
> same boat.  If this is to change, we need to do a lot more work to
> justify it, and to give at least full one version of notice before
> enforcing it.

Indeed.  Not to mention that a new opcode would have to be invented to
signal the end of the except block.

> > 2) Add an optional boolean clear argument to sys.exc_info()
> >     This is lame, but it gives the user one way out.
> 
>   exc_info(...)
>     exc_info() -> (type, value, traceback)
> 
>     Return information about the exception that is currently being handled.
>     This should be called from inside an except clause only.
> 
> Adding an argument to this function reeks of a kludge.  Its job is
> to return information, and should not take any magic arguments to
> make it a 'one-shot'.

Agreed; -1 on this particular API.

> > 3) Add an extra reset_exp function to sys.
> >     More lame since it requires an extra function,
> >     just to patch a "feature".
> 
> This one gets my vote (if this were a democracy).  "Explicit is
> better than implicit".  The new symbol in the sys namespace also
> makes it easy to test for the capability (without a version number
> check).  Maybe it should be called 'clear_exc' or 'reset_exc_info'
> (to match the C API name).

Let's call it exc_reset() or exc_clear().

> > 4) Keep things as they are, and expect the Spanish Inquision.
> 
> I'm even okay with the status quo and can continue to use my current
> hack to clear exception data.

You can always clear it by raising and catching another exception. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)