我正在尝试编写类似的代码:
<?php
$includes = array(
'non_existing_file.php', //This file doesn't exist.
);
foreach ($includes as $include) {
try {
require_once "$include";
} catch (Exception $e) {
$message = $e->getMessage();
echo "
<strong>
<font color=\"red\">
A error ocurred when trying to include '$include'.
Error message: $message
</font>
</strong>
";
}
}
我试过require_once
and include_once
,但try catch
没有发现异常。
我怎样才能捕捉到这个致命错误/警告异常?