/**
* 方式二:自定义异常类
* Class ErrorToException
*/
//显示所有的错误
error_reporting(-1);
class ErrorToException extends Exception{
public static function handle($errno,$errstr)
{
throw new self($errstr,0);
}
}
set_error_handler(array('ErrorToException','handle'));
set_error_handler(array('ErrorToException','handle'),E_USER_WARNING|E_WARNING);
try{
echo $test;//notice,不会被处理
echo gettype();//warning
//手动触发错误
trigger_error('test',E_USER_WARNING);
}catch (Exception $exception){
echo $exception->getMessage();
}
/**
* 方式一:ErrorException错误异常类
* @param $errno
* @param $errstr
* @param $errfile
* @param $errline
* @throws ErrorException
*/
function exception_error_handler($errno,$errstr,$errfile,$errline){
throw new ErrorException($errstr,0,$errno,$errfile,$errline);
}
set_error_handler('exception_error_handler');
try{
echo gettype();
}catch (Exception $exception){
echo $exception->getMessage();
}