PHPSTAN:捕获异常而不抛出异常

PHPSTAN : catch an exception without throwing it

大家好,我有这个简单的 try catch 片段,写在 PHP :

    try {
      ...
      // some code
      ...
    } catch (Throwable $e) {
        $response = ['message' => $e->getMessage(), 'trace' => $e->getTraceAsString()];
    }

    return $response;

此代码运行良好,但 PHPSTAN 认为它做得不好:

caught "Throwable" must be rethrown. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception.

我理解消息,但我想知道是否有可能在不抛出异常的情况下捕获异常,并且仍然验证 phpstan 检查?

非常感谢您的阅读,如果您有线索,我接受!

这来自您必须安装的 thecodingmachine/phpstan-strict-rules。如果您对此规则不感兴趣,可以卸载该包。