Why am I getting this error?
Warning: file_get_contents(http://www.example.com) [function.file-get-contents]: failed to open stream: HTTP request failed! in C:\xampp\htdocs\test.php on line 22
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\test.php on line 22
Here is the code:
try {
$sgs = file_get_contents("http://www.example.com");
}
catch (Exception $e) {
echo '123';
}
echo '467';
Aren’t try\catch supposed to continue the excecution of the code? Or maybe there is some different way to do it?
try… catch is more for null object exceptions and manually thrown exceptions. It really isn’t the same paradigm as you might see in Java. Warnings are almost deceptive in the fact that they will specifically ignore try…catch blocks.
To suppress a warning, prefix the method call (or array access) with an
@.Oh, and it is best to view Fatal Exceptions are also completely uncatchable. Some of them can be caught in some circumstances, but really, you want to fix fatal errors, you don’t want to handle them.