try{
$src = imagecreatefromjpeg('https://graph.facebook.com/'.$jsonfriends["data"][$randf]["id"].'/picture');
} catch (Exception $z){
$src = imagecreatefromgif('https://graph.facebook.com/'.$jsonfriends["data"][$randf]["id"].'/picture');
}
在上面的代码中,当'try'块中的代码失败时,控件不会传递到'catch'块。由于https://graph.facebook.com/xxxxxx/picture不是有效的JPEG,因此我得到的输出为错误。实际上,如果它不是JPEG,在这种情况下它将是GIF。那么有谁能帮我解决这个问题吗?如何正确使用Try-Catch异常?
[使用imagecreatefromjpeg和imagejpeg问题]的可能重复(http://stackoverflow.com/questions/1948561/problem-using-imagecreatefromjpeg-and-imagejpeg) – ifaour 2011-05-14 20:11:21