Skip to content

report swallowed exception #5627

Closed
Closed

Description

@staabm

Feature request

A exception thrown is swallowed when the finally block contains a return.
I would expect a error regarding the thrown exception will be swallowed by the php runtime.

today we debugged a class and realized that our exceptions won't get thrown because of such a "finally-return".. its really suprising

https://3v4l.org/OiVkG#v7.4.23
https://phpstan.org/r/8685c7b2-5a0e-4fbb-9e46-dfcca31559b1

Activity

  1. ondrejmirtes commented on Sep 13, 2021

    @ondrejmirtes
    Member

    There's already a rule for multiple returns with finally: https://phpstan.org/r/6cbd1e9b-56e2-40fb-9945-26f9c715caf0

    We could apply it too to "this always thrown exception is shadowed by this return in finally" but I think it's a very rare situation.

  2. staabm commented on Sep 13, 2021

    @staabm
    ContributorAuthor

    think it's a very rare situation.

    experienced it 2 times within the last week. I will see whether I can provide a patch

  3. phpstan-bot commented on Sep 16, 2021

    @phpstan-bot
    Contributor

    @staabm After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

    @@ @@
    -4: Function a() has no return typehint specified.
    +4: Function a() has no return type specified.
    Full report
    Line Error
    4 Function a() has no return type specified.
  4. phpstan-bot commented on Sep 16, 2021

    @phpstan-bot
    Contributor

    @ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

    @@ @@
    - 4: Function a() has no return typehint specified.
    + 4: Function a() has no return type specified.
      6: This return is overwritten by a different one in the finally block below.
      7: Dead catch - Exception is never thrown in the try block.
     10: The overwriting return is on this line.
    Full report
    Line Error
    4 Function a() has no return type specified.
    6 This return is overwritten by a different one in the finally block below.
    7 Dead catch - Exception is never thrown in the try block.
    10 The overwriting return is on this line.
  5. ondrejmirtes commented on Sep 16, 2021

    @ondrejmirtes
    Member
  6. github-actions commented on Oct 18, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  7. locked as resolved and limited conversation to collaborators on Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions