Skip to content

"SyntaxError: cannot have both 'except' and 'except*' on the same 'try'" traceback point to a confusing place #99153

Closed
@ProgramRipper

Description

@ProgramRipper

Bug report

Given the following codes:

try:
    ...
except* Exception:
    ...
except Exception: # SyntaxError here
    ...

# but traceback point here

Traceback:

  File "main.py", line 8
    # but traceback point here
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

and:

try:
    ...
except* Exception:
    ...
except Exception: # SyntaxError here
    ...

def next_scope(): # but traceback point here
    ...

Traceback:

  File "main.py", line 8
    def next_scope(): # but traceback point here
    ^^^
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

The traceback points to a confusing place (the last line of the file or the beginning of the next structure statement) rather than the location of the syntax error.
The traceback I expect is:

  File "main.py", line 5
    except Exception: # SyntaxError here
    ^^^^^^
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

Your environment

  • CPython versions tested on: 3.11.0
  • Operating system and architecture: Ubuntu 22.04 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions