


How to catch errors and display friendly information in PHP_PHP Tutorial
Jul 21, 2016 pm 02:51 PMTo catch errors, you cannot use try{...}catch(){}. The try{...}catch in PHP needs to throw an exception yourself to catch it, which is different from other languages.
Secondly, you can use the following method to achieve the same effect:
error_reporting(0);//Set to block system error prompts and put them at the top of the page
//$string = file_get_contents("index.html");//Normal code
echo 5/0;//Change: 5/8 //Normal code
//If there is an error in the normal code, handle it:
$arr=error_get_last();//Get the error information that just occurred and return an array. If there is no error, return null.
if(isset($arr) ) //If it is not null, it means something went wrong
{
echo "An error occurred, error message:";
print_r($arr); //Specific error information can be modified as needed.
exit;
}
-------------------------------------------------- ---
【echo 5/8;】Output:
0.625
【echo 5/0;】Output:
An error occurred, error message:
Array (
[type] => 2
[message] => Division by zero
[file] => D:wampwwwsinaeditornewfile.php
[line] => 13
)

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
