Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions thrown by callables #78

Open
marcospassos opened this issue Mar 24, 2019 · 2 comments
Open

Exceptions thrown by callables #78

marcospassos opened this issue Mar 24, 2019 · 2 comments

Comments

@marcospassos
Copy link
Collaborator

Currently, wrapping a callable call into a try catch block always results in an error:

try {
    $function();
} catch (\Throwable $exception) {
}
 Throwable is never thrown in the corresponding try block 

In fact, we have no ways to detect which exception can be possibly thrown by an unknown callable. However, we could detect calls to callables inside try blocks and whitelist any exception in the catch.

@marcospassos
Copy link
Collaborator Author

@pepakriz what are your thoughts on this?

@pepakriz
Copy link
Owner

It's known issue: https://github.com/pepakriz/phpstan-exception-rules#anonymous-functions-are-analyzed-at-the-same-place-they-are-declared
Previously, I've tried to solve it in this branch https://github.com/pepakriz/phpstan-exception-rules/tree/catch-and-throw , but the code is unnecessarily complicated and full of black magic.

As you say - detecting callable calls is maybe a good solution until native support for @throws in phpstan-core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants