PHP error handling and exception handling-PHP source code

Source: Internet
Author: User
Tags php error
The following is an article about error handling and exception handling in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the following small series to bring you an article on error handling and exception handling in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.

Error handling:

1. Syntax error
2. runtime errors
3. logical error

Error report:

Error E_ERROR
Warning E_WARNING
Note E_NOTICE


Development Phase: all error reports are output during development, which facilitates debugging.

Running stage: Do not let the program output any error report

Write Error reports to logs

1. specify error report error_reporting = E_ALL (in php. inn)

2. disable error output display_errors = off (in php. ini)

3. enable the error log function log_errors = on (in php. ini)

1. if no error log location is specified by default, logs are written to the web server by default.

2. specify a file name for the error_log option. the file name is an error log.

3. error_log = syslog

 ";?>

Exception handling:An unexpected event occurs during the running of the program. An exception is used to change the normal process of the script.

A new important feature in PHP5


Try {

} Catch (exception object ){

}

1. if there is no problem with the code in try, it will be executed after the code in try is executed.

2. if an exception occurs in the code in try, an exception object (throw) is thrown to the catch parameter, and the content after the exception code appears in try is not executed, directly jump to the catch to execute, the catch is completed, and then continue to execute downward

 "; $ File = @ fopen ("./hello.txt "," r "); if (! $ File) {throw new Exception ("file opening failed");} echo "2222222222
";} Catch (Exception $ e) {echo" 3333333
"; Echo $ e-> getMessage ()."
"; Touch (" hello.txt "); $ file = @ fopen ("./hello.txt "," r ");} echo" 4444444
";?>

In the above discussion, the error handling and exception handling in PHP are all the content that I have shared with you. I hope you can give us a reference and support me a lot.

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.