[Python-3000] Exception re-raising woes
Guido van Rossum
guido at python.org
Fri May 30 20:31:22 CEST 2008
On Fri, May 30, 2008 at 11:10 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Guido van Rossum <guido <at> python.org> writes:
>>
>> That said, it seems you are proposing taking the logical consequence
>> of making except handlers properly nested and scoped,
>
> It's exactly that.
>
>> I would be okay as well with restricting bare raise syntactically to
>> appearing only inside an except block, to emphasize the change in
>> semantics that was started when we decided to make the optional
>> variable disappear at the end of the except block.
>>
>> This would render the following code illegal:
>>
>> def f():
>> try: 1/0
>> except: pass
>> raise
>
> Please note as well that:
>
> def f():
> try: 1/0
> except: pass
> return sys.exc_info()
>
> would return (None, None, None).
> Actually, it already does with the patch I proposed for #2507, and the test
> suite runs fine after fixing a problem in doctest.py.
I'm fine with that. Since in 3.0 sys.exc_info() returns nothing that
isn't accessible from the caught variable, the only reason to use it
is that it makes the exception available to functions *called* from
the except clause. (E.g. logging.exception() works this way.)
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list