I am trying to publish the action of the open graph of the Facebook API, but I get an OAuth exception (#3501) User is already associated to the <object>
. That all is well and good, I expect Facebook to throw this exception. I get some other exceptions related to user authentication (possibly with old / obsolete sessions, regardless).
My question is: has anyone else experienced that this exception is not possible in php? In this particular example (for publishing actions in a graph), I completely wrap the api call in the try / catch statement; but I still get a fatal error.
<?php try { //publishing to open graph $this->fb->api('/me/app:action', 'POST', array( 'object' => 'http://www.domain.com/path/to/graph/object', )); } catch (Exception $e) { /* We may get here if the user has already posted this action before... or if our session somehow went sour or bc facebook is down... or one of any other 1000 reasons the graph api is currently sucking... in any case it doesn't much matter, this is not a mission critical thing to worry about; if we don't post the graph action - we don't post the graph action..nbd. */ }
The above code is a snippet that publishes the graph's action (generalized because its contents are not important for this example).
I understand that the Exception that the PHP PHP SDK throws is FacebookApiException
, but this class extends Exception. I cannot understand for life why in the name of everything is logical, I cannot catch my exception like this.
Has anyone experienced this problem? Is this a bug in the FB PHP SDK? Did I miss something else here? Thanks for your help!
Also, for reference, the relevant parts of the FB PHP SDK are here:
FacebookAPIException Definition (base_facebook.php line 30)
Throwing OAuthException (base_facebook.php line 1105
Change 5/1/12
After several more studies, it turns out that this “Exception” is not really considered an exception at all. Typical exceptions print the stack trace back to the method call, which results in an exception. These "OAuthExceptions" do not. In addition, typical exceptions highlight their error line somewhat differently, for example:
PHP Fatal error: Uncaught exception 'Exception' with message 'foo' /path/to/file.php:10
or
PHP Fatal error: Uncaught exception 'MyException' with message 'stupid php' /path/to/file:10
In this particular case, we are not getting any of this, and it looks more like a typical fatal error:
PHP Fatal error: Uncaught OAuthException: (
I can't understand why this excluded Exception is so weird / erratic.
Decision:
I understood the answer to my question; I added it below - this is a developer error, not an error. The answer is below.
Also, this may very well be part of the error if you want to say that you can refer to the class definition as a hint type to the catch
definition that was not (or was not available) in the current namespace) is an error.