title: Facebook PHP SDK throws uncatchable "GraphMethodException" error
body: <p>I'm experiencing something eerily similar to <a href="https://stackoverflow.com/questions/10402939/facebook-php-sdk-throwing-an-uncatchable-oauthexception">this question about an uncatchable PHP error thrown by the Facebook PHP SDK</a> except for the fact that I'm not using PHP namespaces at all. <a href="https://stackoverflow.com/questions/17808616/facebook-php-sdk-uncaught-graphmethodexception-unsupported-get-request">This other question</a> is also close, but doesn't explain why the error is uncatchable. Further, in my case, I have a Facebook app that issues a Facebook Graph API call against an object that the current user has blocked. This is certainly awkward, but <em>legal for the purposes of this particular app.</em> That means I need to catch the error, not prevent the user from making the search in the first place.</p>
  
  <p>The fatal error's output in my development environment looks like this:</p>
  
  <pre>Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /path/to/apps/lib/facebook/src/base_facebook.php on line 1271</pre>
  
  <p>So, Facebook's Graph API correctly returns an error as a result of the API call, citing "Unsupported get request." However, the Facebook PHP SDK seems to throw this <em>as an uncatchable error,</em> and I don't know why.</p>
  
  <p>I've tried code like the following <code>catch</code> blocks with no success:</p>
  
  <pre><code>try {
      $response = $facebook-&gt;api("/$some_id_of_object_current_user_has_blocked");
  } catch (FacebookApiException $e) {
      // Why does this never get caught?
  } catch (Exception $e) {
      // Similarly, this also never gets caught!
  } catch (GraphMethodException $e) {
      // Still can't catch this exception, and I don't grok why. :(
  }
  </code></pre>
  
  <p>For the sake of ridiculous completeness, I've also tried namespaces including things like this:</p>
  
  <pre><code>try {
      $response = $facebook-&gt;api("/$some_id_of_object_current_user_has_blocked");
  } catch (\FacebookApiException $e) {
  } catch (\Exception $e) {
  } catch (\FacebookApiException\GraphMethodException $e) {
  } catch (\GraphMethodException $e) {
  } catch (... $e) {
  }
  </code></pre>
  
  <p>Further investigation lead me to try catching this in the <code>base_facebook.php</code> file itself, where it seems to get thrown, in <a href="https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L860" rel="nofollow noreferrer">the protected <code>Facebook::_graph</code> method</a>. And sure enough, it <em>is</em> catchable there. The original code at about line 879 of <code>base_facebook.php</code> is:</p>
  
  <pre><code>if (is_array($result) &amp;&amp; isset($result['error'])) {
    $this-&gt;throwAPIException($result);
    // @codeCoverageIgnoreStart
  }
  </code></pre>
  
  <p>Wrapping this call to <code>throwAPIException()</code> with a <code>try...catch</code> block works:</p>
  
  <pre><code>if (is_array($result) &amp;&amp; isset($result['error'])) {
    try {
      $this-&gt;throwAPIException($result);
      // @codeCoverageIgnoreStart
    } catch (Exception $e) {
      // WORKS!
    }
  }
  </code></pre>
  
  <p>So if it works there, why can't I catch this exception from my own scripts? Am I missing something fundamental about the way PHP error handling works?</p>
  
  <p>Alternatively, is there a way for a Facebook app to get a list of all the objects a Facebook user has blocked, such as other Facebook users a user has blocked? I'm familiar with Graph API enough to know that there's a way for an app to access <a href="https://developers.facebook.com/docs/reference/api/page/#blocked" rel="nofollow noreferrer">a list of all users a <em>page</em> has blocked</a>, but that's specifically not what I'm looking for.</p>
  
  <p>Thanks for your time.</p>