[Python-Dev] capturing RETURN_VALUE

Tim Peters tim.peters at gmail.com
Mon Aug 9 01:32:00 CEST 2004


[Tim Peters]
>> It did in your specific example, but not necessarily.  In your
>> specific example, the finally block didn't execute "break" if an
>> exception was raised, it only did "break" if the finally block was
>> entered because of a return.  If it had done "break" in the exception
>> case too, it would have "abandoned" the exception too:

[Christian Tismer]
> Sure, that was by design.
> I'm trying to inline functions into each other, with
> smallest possible changes to the bytecodes of the
> inlined functions. Exceptions shall pass through,
> returns shall be captured and *not* cause the embracing
> function to return, but to continue with the "returned"
> value.

The point was that exceptions and returns act the same way: 
RETURN_VALUE isn't unique here, it's just another instance of leaving
a try-block's suite, the same in this respect as an exception or a
break statement.  That's why it's reliable over time:  it's a general
mechanism at work, not an arbitrary hack specific to RETURN_VALUE.


More information about the Python-Dev mailing list