I have code like this:
try {
$var = $object->getCollection()->first()->getItem()->getName();
} catch(\\Exception $e) {
$var = null;
}
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