代码语言:javascript复制
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
复制代码