Yii2 not catching exception

Hi,

I am using the AWS SDK, put nicely in the vendor folder by Composer.

Everyting works nicely, except when I use Amazon SNS. An exception is thrown:

Aws\Sns\Exception\EndpointDisabledException

Endpoint is disabled

I know what all this means and it no problem to remove this Endpoint. I just can’t get my head around why Yii is quitting, because I am using a try / catch (all) block, like this:




try

							{

							  $this->client->publish(['Message' => $message,

												  'TargetArn' => $key,

												  'MessageStructure' => 'json']);

							  print($value . " - Succeeded!\n");

							}

							catch (Exception $e)

							{

							  $error = $e->getMessage();

							  print($value . " - Failed: " . $error . "!\n");

							 //continue with rest of application

							}



I took this up first with Amazon but they say it can’t be their SDK.

I tried with Yii2 debug settings off, but to no avail.

I am asking here because it did use to work in Yii1.1.

Anybody got a clue what I am overlooking?

Thanks for your wisdom,

Alex

Probably because you are catching the Yii Exception rather than \Exception (the PHP one), which the AWS exception probably inherits from.

It depends on how Exception from the given code is defined. If this is Yii Exception like Lukos said change it to general PHP Exception. If not check if this Aws\Sns\Exception\EndpointDisabledException is not caught earlier and can be rethrown.

Thanks so much guys, \Exception did the trick, so I wasn’t aware that leaving out that backslash called the Yii version of Exception.

See the power of namespaces (or omitting them!)

Alex