Methods for capturing errors and displaying friendly information in PHP _ PHP Tutorial

Source: Internet
Author: User
PHP captures errors and displays friendly information. Capture error, cannot use try {...} catch () {} method, try {...} in PHP {...} catch can be captured only when an exception is thrown by itself, which is different from other languages. Second, you can use the following methods to capture errors. do not use try {...} catch () {} method, try {...} in PHP {...} catch can be captured only when an exception is thrown by itself, which is different from other languages.

Second, you can use the following method to achieve the same effect:

Error_reporting (0); // sets to block system error messages.

// $ String = file_get_contents ("index.html"); // normal code
Echo 5/0; // change: 5/8 // normal code

// If a normal code error occurs, process it:
$ Arr = error_get_last (); // Obtain the error message and return an array. If no error occurs, null is returned.
If (isset ($ arr) // if it is not null, an error occurs.
{
Echo "error, error message :";
Print_r ($ arr); // specific error message, which can be modified as needed.
Exit;
}

--------------------------------------------------

[Echo 5/8;] output:

0.625


[Echo 5/0;] output:

Error. error message:
Array (

[Type] => 2

[Message] => Division by zero

[File] => D: wampwwwsinaeditornewfile. php

[Line] => 13

)

Try {...} catch in PHP requires an exception to be thrown, which is different from other languages. Second, you can use the following method...

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.