PHP custom error handling function trigger_error () _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.