php自定义错误处理用法实例
本文实例讲述了php自定义错误处理用法。分享给大家供大家参考。具体如下:
<?php
error_reporting(E_ALL);
functionErrHandler($errorno,$errorstr,$errorfile,$errorline)
{
$display=true;
$notify=false;
$halt_script=false;
$error_msg="<br>The$errornoerrorisoccurringat$errorlinein
$errorfile<br>";
switch($errorno)
{
caseE_USER_NOTICE:
caseE_NOTICE:
$halt_script=false;
$notify=true;
$label="<B>Notice</B>";
break;
caseE_USER_WARNING:
caseE_WARNING:
$halt_script=false;
$notify=true;
$label="<b>Warning</b>";
break;
caseE_USER_ERROR:
caseE_ERROR:
$label="<b>FatalError</b>";
$notify=true;
$halt_script=false;
break;
caseE_PARSE:
$label="<b>ParseError</b>";
$notify=true;
$halt_script=true;
break;
default:
$label="<b>UnknownError</b>";
break;
}
if($notify)
{
$msg=$label.$error_msg;
echo$msg;
}
if($halt_script)exit-1;
}
$error_handler=set_error_handler("ErrHandler");
echo"<BR><H2>UsingCustomErrorHandler</h2><BR>";
trigger_error("<BR>ErrorcausedbyE_USER_NOTICE</BR>",E_USER_NOTICE);
trigger_error("<BR>ErrorcausedbyE_USER_WARNING</BR>",E_USER_WARNING);
trigger_error("<BR>ErrorcausedbyE_USER_ERROR</BR>",E_USER_ERROR);
trigger_error("<BR>ErrorcausedbyE_PARSE</BR>",E_PARSE);
?>
希望本文所述对大家的php程序设计有所帮助。