PHP 如何捕获 Catchable fatal error?

简介: PHP 如何捕获 Catchable fatal error?
error_reporting(E_ALL);
ini_set("display_errors", "On");
function myErrorHandler($errno, $errstr, $errfile, $errline) {
  if (E_RECOVERABLE_ERROR === $errno) {
    throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
  }
  return false;
}
set_error_handler('myErrorHandler');
for ($i = 0; $i < 5; $i++) {
    try {
        task($i);
    } catch (\Throwable $t) {
        echo " 执行失败,下一个\n";
        continue;
    }
}
function task($task_id)
{
    echo "执行任务 $task_id";
    if ($task_id == 2) {
        echo new stdClass();
    }
    echo " 成功\n";
}
// press Ctrl+Enter to run
目录
相关文章
|
缓存 PHP 开发工具
Composer 更新时报错:PHP Fatal error: composerRequireac6b4…(): Failed opening required ‘…/src/helpers.php
Composer 更新时报错:PHP Fatal error: composerRequireac6b4…(): Failed opening required ‘…/src/helpers.php
233 0
Composer 更新时报错:PHP Fatal error:  composerRequireac6b4…(): Failed opening required ‘…/src/helpers.php
|
PHP Windows
composer PHP Fatal error: Allowed memory size of 报错解决
composer PHP Fatal error: Allowed memory size of 报错解决
146 0
|
PHP 数据格式 XML
PHP Fatal error: Class &#39;DOMDocument&#39; not found
PHP Fatal error:  Class 'DOMDocument' not found 给PHP添加 xml模块: yum install php-xml   如果是PHP5,则用 yum install php55w-xml
1129 0

热门文章

最新文章