PHP Set_error_handler () function

Source: Internet
Author: User
Definition and usage

The Set_error_handler () function sets the user-defined error handling function

This function is used to create the user's own error handling method during runtime.

The function returns the old error handler and returns null if it fails.

Grammar Set_error_handler (error_function,error_types)

Parameter description error_function required to specify the function to run when an error occurs.

Error_types is optional. Specifies the error reporting level at which user-defined errors are displayed. The default is "E_all".

Hints and Notes

Tip: If you use this function, the standard PHP error handler is completely bypassed, and if necessary, the user-defined error handler must terminate (Die ()) script.

Note: If an error occurs before the script executes, the custom error handler is not used because the custom program is not 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: [1024x768] A custom error has been triggerederror on line 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.