PHPset_error_handler () function

Source: Internet
Author: User
PHPset_error_handler () function definition and usage

Set_error_handler () function to set custom error handling functions

This function is used to create your own error handling methods during runtime.

This function returns the old error handler. if it fails, null is returned.

Syntax set_error_handler (error_function, error_types)

The error_function parameter description is required to specify the function to run when an error occurs.

Error_types is optional. Specifies at which error report level a user-defined error will be displayed. The default value is "E_ALL ".

Tips and comments

Tip: If this function is used, it will completely bypass the standard PHP error handler. if necessary, the user-defined error handler must terminate the (die () script.

Note: If an error occurs before the script is executed, the custom error handler will not be used because the custom program has not been registered at that time.

Example

 Custom error: [$errno] $errstr
"; echo " Error on line $errline in $errfile
"; echo "Ending Script"; die(); }//set error handlerset_error_handler("customError");$test=2;//trigger errorif ($test>1) { trigger_error("A custom error has been triggered"); }?>

Output:

Custom error: [1024] A custom error has been triggeredError on line 19 in C:\webfolder\test.phpEnding Script

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.