Reputation: 1918
I have noticed that when uploading images to facebook album via created by my app using the php sdk for facebook, the sdk will occasionally throw an error.
I got an error from the sdk a few times in testing... however I put in a try catch...
try{
$picID = $this->facebook->api('/'.$this->aid.'/photos','post',$photo_details);
var_dump($picID);
}catch(Exception $e){
echo('exception caught '.var_dump($e));
}
and am trying to test it but by dumb luck the error will not occur again. Can someone tell me if I can catch an exception this way?
Thanks.
Upvotes: 1
Views: 2658
Reputation: 33
Don't really want to ressurect a question from 2012 but this has changed since then for anyone looking into it now. For modern code using Facebook SDK 5.x.x use the code...
try {
//Do something with the facebook code here
catch (FacebookSDKException $e) {
//Handle the exception here
//This will only catch exceptions thrown by the SDK but will cover them all, even ones thrown by libraries called by the SDK.
}
Upvotes: 2
Reputation: 76250
Try with:
try {
$picID = $this->facebook->api('/'.$this->aid.'/photos','post',$photo_details);
} catch(CurlException $e) {
echo('exception caught '.$e->getMessage());
}
Upvotes: 6