Can't catch symfony FatalErrorException

后端 未结 4 477
感情败类
感情败类 2020-12-29 19:29

I have code like this:

try {
    $var = $object->getCollection()->first()->getItem()->getName();
} catch(\\Exception $e) {
    $var = null;
}
         


        
4条回答
  •  悲哀的现实
    2020-12-29 19:36

    Works for me (PHP 7.0, Symfony 3.0.9):

    use Symfony\Component\Debug\Exception\FatalThrowableError;
    ...
    try {
        throw new FatalErrorException("something happened!", 0, 1, __FILE__, __LINE__);
    } catch (FatalErrorException $e) {
        echo "Caught exception of class: " . get_class($e) . PHP_EOL;
    }
    

    Output:

    Caught exception of class: Symfony\Component\Debug\Exception\FatalErrorException

提交回复
热议问题