2

我正在编写一个应用程序,我认为所有错误都在处理中,包括致命错误。

但是现在我发现了一个导致白屏的错误,并且该错误仅显示在网络服务器日志中。

$nonExistentVar + 1; // Notice error, gets caught and pretty error is displayed

$existentVar->nonExistentMethod(); // Fatal error, gets caught and pretty error is displayed

$nonExistentVar->nonExistentMethod(); // White screen, error can be seen in nginx.error.log

最后一个错误是无法捕获的吗?或者问题可能是什么?

我正在使用 Silex,不确定这是否重要。

4

2 回答 2

0

按照我的理解,可以捕获异常但不能捕获致命错误。我很想知道您是如何“捕捉”示例 #2 中的致命错误的?

is_a()为什么不在尝试调用该方法之前使用 php测试来查看 $nonExistentVar 是否属于正确的类?method_exists()或者,如果您仍然不知道某个类是否有可用的给定方法,也可能结合使用。

于 2013-08-05T00:05:44.457 回答
0

试着只放最后一行:

$nonExistentVar->nonExistentMethod();

这对我有用,因为Symfony\Component\Debug\ExceptionHandler在遇到第一个时立即发送响应Error

public function handle(\Exception $exception)
{
    if (class_exists('Symfony\Component\HttpFoundation\Response')) {
        $this->createResponse($exception)->send();
    } else {
        $this->sendPhpResponse($exception);
    }
}
于 2013-08-13T07:28:57.257 回答