PHP Custom error handling function Trigger_error () _php Tips

Source: Internet
Author: User
Definition and usage the Trigger_error () function creates a user-defined error message.
Trigger_error () is used to trigger an error message under a user-specified condition. It is used in conjunction with a built-in error processor, or it can be used with a user-defined function created by the Set_error_handler () function.

If an illegal error type is specified, the function returns FALSE, otherwise returns true.
Grammar Trigger_error (error_message,error_types)
Parameter description error_message required. Specify an error message. Length is limited to 1024 characters. Error_types Optional. The type of error that prescribes the error message. Possible values: E_user_error
e_user_warning
E_user_notice
Copy Code code 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 with Input must>=0 ', e_user_error);
}
?>

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.