[Python-bugs-list] [Bug #115143] Python sometimes complains about continue in an except

noreply@sourceforge.net noreply@sourceforge.net
Tue, 3 Oct 2000 11:06:18 -0700


Bug #115143, was updated on 2000-Sep-22 14:57
Here is a current snapshot of the bug.

Project: Python
Category: Parser/Compiler
Status: Closed
Resolution: Duplicate
Bug Group: None
Priority: 4
Summary: Python sometimes complains about continue in an except

Details: If a continue statement occurs in the second try/except
statement nested within another try statement, it complains
about the second continue.  For example, this code generates a SyntaxError:

    for i in range(10):
        try:
            try:
                pass
            except:
                continue
            try:
                pass
            except:
                continue
        except:
            pass

while this is fine:

    for i in range(10):
        try:
            pass
        except:
            continue
        try:
            pass
        except:
            continue

This problem exists in both 1.5.2 and 2.0b1.

A workaround is to raise "continue" from the inner 
try/except statements and catch it in the outer try/except:

    for i in range(10):
        try:
            try:
                pass
            except:
                raise "continue"
            try:
                pass
            except:
                raise "continue"
        except "continue":
            continue
        except:
            pass



Follow-Ups:

Date: 2000-Oct-03 11:06
By: gvanrossum

Comment:
This really is a duplicate of #110830, which was "resolved" as a feature request (i.e. won't be fixed any time soon).

A 'continue' inside a 'try' clause is invalid (because it's too complicated to generate code for it that cleans up the try block). Your continue is still inside a 'try' clause -- it is inside the *outer* 'try' clause! So it's the same bug.

You don't need two inner try-except clauses with a continue stmt to reproduce this; one is enough (it complains about the last one due to the way the code generator signals errors).
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=115143&group_id=5470