PHP Custom error handling function Trigger_error () _php Tutorial

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

  • 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.