本文实例讲述了php自定义错误处理用法。分享给大家供大家参考。具体如下:
<?php
error_reporting(e_all);
function errhandler($errorno, $errorstr, $errorfile, $errorline)
{
$display = true;
$notify = false;
$halt_script = false;
$error_msg = "<br>the $errorno error is occurring at $errorline in
$errorfile<br>";
switch($errorno)
{
case e_user_notice:
case e_notice:
$halt_script = false;
$notify = true;
$label = "<b>notice</b>";
break;
case e_user_warning:
case e_warning:
$halt_script = false;
$notify = true;
$label = "<b>warning</b>";
break;
case e_user_error:
case e_error:
$label = "<b>fatal error</b>";
$notify=true;
$halt_script = false;
break;
case e_parse:
$label = "<b>parse error</b>";
$notify=true;
$halt_script = true;
break;
default:
$label = "<b>unknown error</b>";
break;
}
if($notify)
{
$msg = $label . $error_msg;
echo $msg;
}
if($halt_script) exit -1;
}
$error_handler = set_error_handler("errhandler");
echo "<br><h2>using custom error handler</h2><br>";
trigger_error("<br>error caused by e_user_notice</br>", e_user_notice);
trigger_error("<br>error caused by e_user_warning</br>", e_user_warning);
trigger_error("<br>error caused by e_user_error</br>", e_user_error);
trigger_error("<br>error caused by e_parse</br>", e_parse);
?>
希望本文所述对大家的php程序设计有所帮助。
评论列表:
发布于 3天前回复该评论
发布于 3天前回复该评论
发布于 3天前回复该评论
发布于 3天前回复该评论
发布于 2天前回复该评论
发布于 2天前回复该评论
发布于 2天前回复该评论
发布于 2天前回复该评论