classification
Title: break in finally discards exception
Type: behavior Stage:
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eallik, mark.dickinson, yselivanov
Priority: normal Keywords:

Created on 2012-09-24 18:27 by eallik, last changed 2012-09-24 19:27 by mark.dickinson. This issue is now closed.

Messages (6)
msg171168 - (view) Author: Erik Allik (eallik) Date: 2012-09-24 18:27
This is either a bug, or a very weird but undocumented feature/caveat.


def fn1():
    while True:
        try:
            raise Exception()
        finally:
            pass
def fn2():
    while True:
        try:
            raise Exception()
        finally:
            break  # <-----
fn1()  # exception, as expected
fn2()  # silence!
msg171169 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-09-24 18:42
This *was* a documented feature until very recently;  it looks as though a recent doc change inadvertently removed it from the documentation.  See

http://hg.python.org/cpython/rev/bef098bd3fa5

and the associated issue, issue 14167.
msg171176 - (view) Author: Erik Allik (eallik) Date: 2012-09-24 18:55
It looks to me that it was not removed from the doc but explicitly changed to say that 'break' does not cause the exception to be discarded, unless I'm misunderstanding it:

    1.20 +:keyword:`finally` clause is executed.  If there is a saved exception
    1.21 +or :keyword:`break` statement, it is re-raised at the end of the
    1.22 +:keyword:`finally` clause. If the :keyword:`finally` clause raises
msg171178 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-09-24 19:02
Hmm.  Yes, true.  Either way, it's the docs that need to be fixed rather than the behaviour.

Thanks for catching this!
msg171179 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2012-09-24 19:02
see the issue 14167
msg171185 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-09-24 19:27
That portion of the documentation has been restored.  Closing this issue.
History
Date User Action Args
2012-09-24 19:27:48mark.dickinsonsetstatus: open -> closed

assignee: docs@python
components: + Documentation
versions: + Python 3.2, Python 3.3
nosy: + docs@python

messages: + msg171185
resolution: fixed
2012-09-24 19:02:43yselivanovsetnosy: + yselivanov
messages: + msg171179
2012-09-24 19:02:00mark.dickinsonsetmessages: + msg171178
2012-09-24 18:55:28ealliksetmessages: + msg171176
2012-09-24 18:42:47mark.dickinsonsetnosy: + mark.dickinson
messages: + msg171169
2012-09-24 18:27:59eallikcreate