Say the website building language, we all know PHP, because PHP website construction has been everywhere, today we
Jinan website ProductionHttp://www.jnwebseo.com to talk about how to use PHP to customize the error handling function, the bottom of the direct code.
function MyErrorHandler ($errno, $errstr, $errfile, $errline) {
if (! ( Error_reporting () & $errno)) {return;}
Switch ($errno) {
Case E_USER_ERROR:
echo "My ERROR [$errno] $errstr
";
echo "Error line: $errline in file: $errfile
";
echo "PHP version:". Php_version. " (" . Php_os. ")
";
Break
Case e_user_warning:
echo "My WARNING [$errno] $errstr
";
Break
Case E_user_notice:
echo "My NOTICE [$errno] $errstr
";
Break
Default
echo "Unknown error type: [$errno] $errstr
";
Break
}
return true;
}
function Trigger_test ($age) {//The test function that throws the error
if ($age <= 0 | | $age > 999) trigger_error ("Age not valid: $age years old", E_user_error);
if ($age < Trigger_error) ("Minors: $age Years", e_user_warning);
if ($age > && $age < Trigger_error) ("Slightly older: $age years old", E_user_notice);
}
If the error is handled simply and uniformly:
$errorHandler = Set_error_handler ("MyErrorHandler");
Trigger_test (1000);//throws an error level
function Myerror ($errno, $errstr, $errfile, $errline) {
Print_r (Func_get_args ());
Specific Treatment methods
}
function mywarning ($errno, $errstr, $errfile, $errline) {
Print_r (Func_get_args ());
Specific Treatment methods
}
function Myntice ($errno, $errstr, $errfile, $errline) {
Print_r (Func_get_args ());
Specific Treatment methods
}
If you want to handle different levels of errors individually:
Set_error_handler (' Myerror ', e_user_error);
Set_exception_handler (' mywarning ', e_user_warning);
Set_exception_handler (' Myntice ', e_user_notice);
Trigger_error (' intentionally throwing a mistake, or a very serious one! ', e_user_error);
http://www.bkjia.com/PHPjc/477306.html www.bkjia.com true http://www.bkjia.com/PHPjc/477306.html techarticle say the website building language, everybody knows PHP, because PHP website construction already everywhere, today our Jinan website production http://www.jnwebseo.com to talk about is how to use PHP custom error ...