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 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_NOTICECopy codeThe Code is as follows: <? Php
Function myError ($ errno, $ errstr, $ errfile, $ errline ){
Switch ($ errno ){
Case E_USER_ERROR:
Echo "<B> My ERROR </B> [$ errno] $ errstr <br/> ";
Echo "Fatal error in line $ errline of file $ errfile ";
Exit (1 );
Break;
Case E_USER_WARNING:
Echo "<B> My WARNING </B> [$ 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 );
}
?>