Php Flow » Facebook, Php

How To Handle Exception :PHP /Facebook Api

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

Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>