so I'm grabbing some information from an XML file like so:
$url = "http://myurl.blah";
$xml = simplexml_load_file($url);
Except sometimes the XML file is empty and I need the code to fail gracefully but I can't seem to figure out how to catch the PHP error. I tried this:
if(isset(simplexml_load_file($url)));
{
$xml = simplexml_load_file($url);
/*rest of code using $xml*/
}
else {
echo "No info avilable.";
}
But it doesn't work. I guess you can't use ISSET that way. Anyone know how to catch the error?
try {} catch (exception $e) {}pair.simplexml_load_file()does not throw exceptions. It raisesE_WARNINGerrors.simplexml_load_filewas built-in... you may find the tip helpful on the [documentation page](php.net/simplexml_load_file):Use libxml_use_internal_errors() to suppress all XML errors, and libxml_get_errors() to iterate over them afterwards.