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
)