Before raising the question I referred below answers
As I am not getting clarity on this, I am raising this question. So please someone don't close this question as it is duplication.
I have below PHP script to get upto date currency value. Since I am using an API, I guess there may be some downtime or similar. So I have to assign a default value if API is not providing.
I know there are some other methods like isset() and !empty()
But I would like to use try{} catch(){}
Below script doesn't have any error it works fine.
<?php
try {
$return = file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22AEDUSD%22%29&env=store://datatables.org/alltableswithkeys");
$xml=simplexml_load_string($return) or die("Error: Cannot create object");
$coversionRate = (string)$xml->results->rate->Rate;
echo '<pre>'; print_r($coversionRate);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
Now, I have made a mistake in API URL, so it should go catch() block and should give soft message. But it throws warning message.
Can I use try(){..} catch() {..} in this scenario or not?