How PHP captures the error and displays friendly information

Source: Internet
Author: User

Catch error, cannot use try{...} The way of catch () {}, PHP inside try{...} Catch is an exception that needs to be thrown by itself to catch and distinguish it from other languages.

Second, you can achieve the same effect using the following methods:

Error_reporting (0)//Set shield system error prompt, put the top of the page

$string = file_get_contents ("index.html");/Normal Code
echo 5/0;//Change: 5/8//Normal code

If the normal code fails, it is handled:
$arr =error_get_last ()//Gets the error message that just occurred, returns an array, and returns null without error.
if (Isset ($arr))//is not NULL, it indicates an error
{
echo "went wrong, error message:";
Print_r ($arr); The specific error message can be modified as needed.
Exit
}

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

"Echo 5/8;" Output:

0.625


"Echo 5/0;" Output:

Error message:
Array (

[Type] => 2

[Message] => division by zero

[File] => d:wampwwwsinaeditornewfile.php

[Line] => 13

)

Related Article

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.