I know that we try catch in PHP to catch Exceptions, but about half of my interviewers said that try catch can catch a fatal error. I tried it and it doesn't work that way by default. Function set_error_handler can catch errors. And now I have doubts. Is there some way to configure PHP so it can catch a fatal error (or other errors) with try catch? I got doubts, because I found this pieces of code in my project
try {
//sometimes $sFile is not initialized
$sPath = $sProducerOutput . $sFile;
} catch (\Exception $oException) {
$sPath = false;
}
try {
$sJson = json_encode($aArgs['sJson']);
}
catch(\Exception $oException) {
$bError = true;
$sMessage .= 'Unable to json_encode: ' . print_r($aArgs['sJson'], true) . ')'."\n";
}