I have code like this:
try {
$var = $object->getCollection()->first()->getItem()->getName();
} catch(Exception $e) {
$var = null;
}
Of course i have communicative variable and method names. This is just demonstration.
So if my collection is empty the Collection::first() will return false. Then the getItem call will throw a SymfonyComponentDebugExceptionFatalErrorException which won't be catched by the code above.
My question is that how can i catch this exception? I have long chains like this with many getters that can return null. So i prefer this way rather than checking every value for null.
question from:https://stackoverflow.com/questions/28406566/cant-catch-symfony-fatalerrorexception