繁体   English   中英

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

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

我从facebook SDK获得此异常:

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

如何在打印此消息之前捕获异常? 我想把它改成这样的东西:

应用程序的响应仍然相同,因此我们无法再将其发布到您的墙上:)

顺便说一句,有一个方法(下面)处理所有异常,我只希望这个新消息的特定情况。

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;
  }

谢谢。

您将抛出异常的代码放在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