PHP Error and exception handling

Source: Internet
Author: User

There are three error reports in PHP:

1. Error, parsing error, fatal error
2. Warning
3. Note

Fatal error, error, will terminate the execution of the program, syntax error, PHP did not execute
Warning, he will not terminate the operation, but will affect the result
Note-* Does not terminate execution and does not affect results


In order for the user to get a better experience, we block out all the wrong output, which is the output, not the display
But in this case, the administrator can not see the error.

Errors are not displayed on the page, and errors are generated with a log that is provided to the administrator for viewing.

Error_reporting (~e_all) shielded all output, and naturally, the administrator could not see the

I don't want to block all the output, I just block all the display

Ini_set (' display_errors ', ' off '); indicates that all errors on the page are masked, but there is no error blocking the output

Ini_set (' Log_errors ', ' on ');    // Turn on log write function Ini_set // where the logs are stored Ini_set (' display_errors ', ' off ');    // Shielded page Display error_reporting (e_all);    // Output All Errors
echo 123; Echo $str;    // This will show a note indicating that the variable is not declared Echo Date ();  // warning, no reference Echo Dae ();   // fatal error, unable to find this function Echo 123;

Abnormal:

in Phpjava 

throws an exception, which is One of the reasons why the exception handling statements are rarely seen in PHP source code.

<? PHP // if PHP has built-in exception classes that handle dividend cannot be zero, then it is not necessary to manually throw the $a = 5; $b = 0; Try {    echo$a$bcatch (Exception$ E) {    echo ' found abnormal ';        } // In this case, the capture statement is not executed, and the error message is still displayed on the page: Warning:division by Zero

<?PHP//PHP cannot automatically throw exceptions, so we need to throw them manually$a= 5;$b= 0;Try {    if($b= = 0)Throw New Exception(' Divisor is zero '); Echo $a/$b;} Catch(Exception $e) {    Echo' Produce an exception: '.$e-getMessage ();}

page Output: generates an exception: the divisor is zero

PHP Error and exception handling

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.