When you try to retrieve a non-exist object from an exists bucket, It should throw NoSuchKeyException, not NoSuchBucketException.
Test code:
$client = new Client(array(
'region' => 'gz',
'credentials' => array(
'appId' => '{appId}',
'secretId' => '{secretId}',
'secretKey' => '{secretKey}'
)
));
try {
$result = $client->headObject(array(
'Bucket' => '{exists bucket}',
'Key' => '{non-exists key}'
));
print_r($result);
} catch ( NoSuchKeyException $e ) {
echo 'No such key.';
} catch ( NoSuchBucketException $e) {
echo 'No such bucket.';
}
The output will be "No such bucket."