Possible Duplicate:
How to catch curl errors in PHP
I have got some lines of code:
<?php
try {
$my_curl = curl_init();
curl_setopt($my_curl, CURLOPT_URL, $one_url);
curl_setopt($my_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($my_curl, CURLOPT_BINARYTRANSFER, 1);
$datum = curl_exec($my_curl);
curl_close($my_curl);
$my_image = imagecreatefromstring($datum);
} catch(Exception $e) {
var_dump($e->getMessage());
}
?>
When running in real environment, some sites which contain images (as $one_url
) cannot access or died or ... cause one/ or many of lines of code turn into errors.
How can I try - catch if any statement cannot be done successfully? In other words, I like try - catch works like... switch - case (not if else).
Any advice will be greatly appreciated! Thank you very much.