PHP custom error handling function trigger_error (). Define and use the trigger_error () function to create user-defined error messages. Trigger_error () is used to trigger an error message under the conditions specified by the user. It is defined and used with the built-in error processor trigger_error () function to create user-defined error messages.
Trigger_error () is used to trigger an error message under the conditions specified by the user. It is used together with the built-in error processor, or with user-defined functions created by the set_error_handler () function.
If an invalid error type is specified, the function returns false; otherwise, the function returns true.
Syntax trigger_error (error_message, error_types)
The error_message parameter description is required. Specifies the error message. It can be up to 1024 characters in length. Error_types is optional. Specifies the error type of the error message. Possible value: • E_USER_ERROR
• E_USER_WARNING
• E_USER_NOTICE
The 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 );
}
?>
The Parse () function creates a user-defined error message. Trigger_error () is used to trigger an error message under the conditions specified by the user. It works with built-in Error Processor 1...