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...