<br><br><div class="gmail_quote">2009/7/18 Stephen J. Turnbull <span dir="ltr"><<a href="mailto:stephen@xemacs.org">stephen@xemacs.org</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Greg Ewing writes:<br>
 > Michael wrote:<br>
 > > Here are two examples of why allowing return inside a finally block is<br>
 > > a bad idea:<br>
 ><br>
 > Don't do those things, then!<br>
 ><br>
 > Nobody is *forcing* you to write returns inside<br>
 > finally blocks.<br>
<br>
</div>+1<br>
<br>
Why not just emphasize in the documentation that return (etc) in a<br>
finally: suite *will* get executed *after* return or an exception is<br>
raised in the try: suite?  </blockquote><div><br>That exceptions can be silently swallowed in a finally block (which is 'expected' and usually intended to propagate exceptions) in the presence of a return (or a break apparently) is worrying.<br>
<br>Another solution would be to have the exception raised instead of swallowed. There is a harder migration regarding backwards compatibility though - you can only warn when the exception is swallowed which may never be seen by the programmer.<br>
<br>Michael<br><br><br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">"These stunts were performed by<br>
professionals.  Don't try this at home, kids."<br>
<br>
More specifically, maybe there should be an explicit warning that in a<br>
finally: suite<br>
<br>
    if exit_condition:<br>
        return<br>
    do_work()<br>
    # end of suite<br>
<br>
has (perhaps surprisingly, YMMV) different semantics from<br>
<br>
    if not exit_condition:<br>
        do_work()<br>
    # end of suite<br>
<br>
WDOT?<br>
<div><div></div><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br><br><br>