This is a simple question when one hour at Google does not seem to allow it. How do you catch failure in PHP? For the following code:
try { include_once 'mythical_file'; } catch (Exception $e) { exit('Fatal'); } echo '?';
With a mythical file that does not exist, I get the output of '?'. I know that PHP cannot catch failure because it causes a warning error, but here? What is the best way to catch failure? For example, the following works:
(include_once 'unicorn') or exit('!');
but this does not throw an exception, so I cannot get the context of the file, line and stack.
include php try-catch
fabjoa
source share