PHP自定义错误和异常

PHP自定义错误和异常

<?php
// 错误处理函数
function customError($errno, $errstr)
{
    echo "<b>Error:</b> [$errno] $errstr";
}

// 设置错误处理函数
set_error_handler("customError");

// 触发错误
echo($test);
echo '</br>';
echo '</br>';

set_exception_handler('handle_exception');
 
throw new Exception("Value must be 1 or below"); //抛出异常
 
function handle_exception($exception) {
       echo $exception;
}
 

 TP E自定义异常 写appException()这个

原文地址:https://www.cnblogs.com/newmiracle/p/14121249.html