简体   繁体   English

如何从facebook sdk捕获并更改抛出的异常消息?

[英]How can I catch and change the thrown exception message from facebook sdk?

I'm getting this exception from facebook SDK: 我从facebook SDK获得此异常:

Fatal error: Uncaught OAuthException: (#506) Duplicate status message thrown in [...] src/base_facebook.php on line 1033

How can I catch the exception before it prints this message? 如何在打印此消息之前捕获异常? I want to change it to something like this: 我想把它改成这样的东西:

The response of the application still the same so we can't publish it in to your wall again : ) 应用程序的响应仍然相同,因此我们无法再将其发布到您的墙上:)

Btw, there is a method (below) that handles all the exceptions and I want this new message only for that especific case. 顺便说一句,有一个方法(下面)处理所有异常,我只希望这个新消息的特定情况。

protected function throwAPIException($result) {
    $e = new FacebookApiException($result);
    switch ($e->getType()) {
      // OAuth 2.0 Draft 00 style
      case 'OAuthException':
        // OAuth 2.0 Draft 10 style
      case 'invalid_token':
        $message = $e->getMessage();
      if ((strpos($message, 'Error validating access token') !== false) ||
          (strpos($message, 'Invalid OAuth access token') !== false)) {
        $this->setAccessToken(null);
        $this->user = 0;
        $this->clearAllPersistentData();
      }
    }

    throw $e;
  }

Thanks. 谢谢。

You put the code that is throwing the Exception within a try block and then catch it with a catch block: 您将抛出异常的代码放在try块中,然后使用catch块捕获它:

try
{
  // Code goes here
}

catch (OAuthException $e)
{
  // Stuff to do with exception
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM