Define and use the Trigger_error () function to create a user-defined error message.
Trigger_error () is used to trigger an error message under user-specified conditions. It is used in conjunction with the built-in error handler or with a user-defined function created by the Set_error_handler () function.
If an illegal error type is specified, the function returns false, otherwise true.
Grammar Trigger_error (error_message,error_types)
Parameter description error_message required. Specifies the error message. The length limit is 1024 characters. Error_types is optional. Specifies the error type of the error message. Possible value: E_user_error
e_user_warning
E_user_notice
Copy CodeThe code is as follows:
function Myerror ($errno, $errstr, $errfile, $errline) {
Switch ($errno) {
Case E_USER_ERROR:
echo "
My ERROR[$errno] $errstr
";
echo "Fatal error in line $errline of file $errfile";
Exit (1);
Break
Case e_user_warning:
echo "
My WARNING[$errno] $errstr ";
Break
Default
echo "Unknown error type:[$errno] $errstr";
Break
}
}
Set_error_handler ("Myerror");
$age =-100;
if ($age <0) {
Trigger_error (' Age you input must>=0 ', e_user_error);
}
?>
http://www.bkjia.com/PHPjc/326714.html www.bkjia.com true http://www.bkjia.com/PHPjc/326714.html techarticle define and use the Trigger_error () function to create a user-defined error message. Trigger_error () is used to trigger an error message under user-specified conditions. It with built-in error processor one ...