today we will discuss how to handle exception with Facebook graph api and php.Normally when we will create a Facebook api object, if error exist then we did not get any thing as a output, we just see a blank page.
As a point of developer view, we did not identified what problem accrued to connecting with Facebook.
In programming language we have exception class to handle all exception related issues. Facebook Api already provide his custom exception class to catch exception when error accord.
What is exception:
An exception is saving the current state of execution in a predefined place and switching the execution to a specific subroutine known as an exception handler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
try {
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRETCODE,
'cookie' => true,
));
return $facebook;
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
FacebookApiException class handle all exception related issues which will accrued when we communication with Facebook server. It will return user friendly message to identify problems.
OutPut Error Example:
Received HTTP code 407 from proxy after CONNECT