PHP set_error_handler () function

Source: Internet
Author: User

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 will return the old error handlingProgramIf it fails, null is returned.

SyntaxSet_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, the standard PHP error handler function is completely bypassed. 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

<? PHP  // Error handler Function  Function Customerror ( $ Errno , $ Errstr , $ Errfile , $ Errline  ){  Echo "<B> custom error: </B> [ $ Errno ] $ Errstr <Br/>" ;  Echo "Error on line $ Errline In$ Errfile <Br/>" ;  Echo "Ending script" ;  Die  ();}  //  Set error handler  Set_error_handler ("Customerror" );  $ Test = 2 ;  //  Trigger Error  If ($ Test > 1 ){  Trigger_error ("A custom error has been triggered" );} ?>

Output:

 
Custom error: [1, 1024] A custom error has been triggerederror on line19 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.