Exceptions thrown by callables
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.
@pepakriz what are your thoughts on this?
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.