这是一个无法捕捉的致命错误吗?

时间:2013-08-04 23:27:33

标签: php nginx silex

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

但现在我发现一个导致白屏的错误,错误只显示在网络服务器日志中。

$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,不确定这是否重要。

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分: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);
    }
}
相关问题