i am searching for a simple way to catch JSON-Errors and put out my own Errormessage. To give you an example, i have code that looks like this:
$response = json_decode(file_get_contents($url));
This works totally fine, but after while the URL does not contain more content. I know that, and it is totally fine, but i do not want that an error gets thrown all the time that looks like this:
Warning: file_get_contents(http://example.com/getcontent.php): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD REQUEST in C:\Program Files... on line 153
The first thing i tried was to make a try/catch-statement which looked like this:
try
{
$response = json_decode(file_get_contents($url));
}
catch (Exception $e)
{
echo "Error!";
}
This did not change anything.
Thank you very much in advance!