Skip to content

S110 only works for Exception not other exception types for multi-line try blocks #17770

@shearer12345

Description

@shearer12345

Summary

For multi-line try blocks S110 only detects for Exception - other exception types (e.g. RuntimeError) stop it detecting.

See playground link for reproduction

Also relates to #8593 - where S110 is suggested for that case.

# Detected by S110
try:
    i = 42
    j = 24
except Exception:
    pass

# Not detected by S110
try:
    i = 42
    j = 24
except RuntimeError:
    pass

gives

$ ruff check --isolated --select S110 test.py
test.py:3:1: S110 `try`-`except`-`pass` detected, consider logging the exception
  |
1 |   try:
2 |       i = 42
3 | / except Exception:
4 | |     pass
  | |________^ S110
5 |
6 |   try:
  |

Found 1 error.

Version

ruff 0.11.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions