title: How can I catch and change the thrown exception message from facebook sdk?
body: <p>I'm getting this exception from facebook SDK:</p>
  
  <pre><code>Fatal error: Uncaught OAuthException: (#506) Duplicate status message thrown in [...] src/base_facebook.php on line 1033
  </code></pre>
  
  <p>How can I catch the exception before it prints this message?
  I want to change it to something like this:  </p>
  
  <blockquote>
    <p><em>The response of the application still the same so we can't publish it in to your wall again : )</em></p>
  </blockquote>
  
  <p>Btw, there is a method (below) that handles all the exceptions and I want this new message only for that especific case.</p>
  
  <pre><code>protected function throwAPIException($result) {
      $e = new FacebookApiException($result);
      switch ($e-&gt;getType()) {
        // OAuth 2.0 Draft 00 style
        case 'OAuthException':
          // OAuth 2.0 Draft 10 style
        case 'invalid_token':
          $message = $e-&gt;getMessage();
        if ((strpos($message, 'Error validating access token') !== false) ||
            (strpos($message, 'Invalid OAuth access token') !== false)) {
          $this-&gt;setAccessToken(null);
          $this-&gt;user = 0;
          $this-&gt;clearAllPersistentData();
        }
      }
  
      throw $e;
    }
  </code></pre>
  
  <p>Thanks.</p>