title: Cannot catch AWS S3 exception
body: <p>I'm trying to get the filesize of an S3 object using the Stream API with the following code:</p>
  
  <pre><code>try{
      $fileSize = filesize("s3://".$bucket."/".$filename);
  }catch(Aws\S3\Exception\NoSuchKeyException $e) {
      return false;
  }
  </code></pre>
  
  <p>If the key doesn't exist I get the following error:</p>
  
  <blockquote>
    <p>[Tue Oct 13 23:03:32 2015] [error] [client 54.225.205.152] PHP Warning:  File or directory not found: s3://mybucket/myfile.jpg in /var/www/vendor/aws/aws-sdk-php/src/Aws/S3/StreamWrapper.php on line 774 </p>
    
    <p>[Tue Oct 13 23:03:32 2015] [error] [client 54.225.205.152] PHP Warning:  filesize(): stat failed for s3://mybucket/myfile.jpg in /var/www/api-dev/awsFunc.php on line 278 </p>
    
    <p>[Tue Oct 13 23:03:32 2015] [error] [client 54.225.205.152] PHP Fatal error:  Uncaught Aws\S3\Exception\NoSuchKeyException: AWS Error Code: NoSuchKey, Status Code: 404, AWS Request ID: 4A6F1372301D02F7, AWS Error Type: client, AWS Error Message: The specified key does not exist., User-Agent: aws-sdk-php2/2.8.21 Guzzle/3.9.3 curl/7.22.0 PHP/5.3.10-1ubuntu3.19\n  thrown in /var/www/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91</p>
  </blockquote>
  
  <p>So, although I explicitly try to catch the Aws\S3\Exception\NoSuchKeyException the system throws it anyway.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I found the error. The exception should namespace should start with '\' instead of Aws, like that:</p>
  
  <pre><code>try{
      $fileSize = filesize("s3://".$bucket."/".$filename);
  }catch(\Aws\S3\Exception\NoSuchKeyException $e) {
      return false;
  }
  </code></pre>
  
  <p>I don't know though why when I <code>use</code> a namespace the namespace doesn't start with '\' but in the exception it needs it. I'd like someone to explain.</p>