[英]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.