Skip to content

NewExceptionsFromToString sniff warns about caught exception #863

@mdio

Description

@mdio

This code fails the sniff even though it is valid because the exception is caught and not bubbled up.

class Foo {
    public function __toString() {
        try {
            throw new \LogicException('should not trigger the sniff');
        } catch (\Exception $e) {
            // ...
        }
    }
}

I fear that it's very hard to check that every thrown exception is really caught because of inheritance, but the sniff is already not a 100% safe because an exception could be raised in a method called in __toString.

So I'd say it's fair to just check if the exception is thrown inside a try block and not for a matching catch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions