LoginSignup
0
0

More than 3 years have passed since last update.

[AWSclient/sdk]Exceptionのerror-handle

Posted at

php-Exception(try-catch構文)のお話し。
AWSclient/sdkのerror-handleで、プチはまりしてしまったので。。

Exceptionのerror-handleについて、サンプルコードを探していると
- Exception
- AwsException
- SnsException
- S3Exception
とかの使い分けを意識できてなかったので。
(モチのロンでしょ、って方には有意義なネタではないですので即終了で。ゴメンナサイ)

コード読み・試作した感じ、正しい実装例としては

sample.php
use Aws\Sns\Exception\SnsException;

function wrap_publish($args)
    // ・・・

    try {
        $ret = $snsClient->publish($args);
    } catch (SnsException $e)
        $ret = false;
    }
    return $ret;
}

な感じです。
つまり、 XxxClientに対してはXxxExceptionをcatchしなさいよ ってだけですね。

C++脳で育った自分的には、Exception・RuntimeExceptionでもcatchできるんだと思ってました。(細かいerror-handleはできないとしても)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0