Catch and throw more detailed exception, when bucket not found 59/24659/2
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 17 Jul 2014 16:44:28 +0000 (18:44 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 18 Jul 2014 06:49:36 +0000 (08:49 +0200)
There was an uncaught out_of_range exception, that can be thrown
by unordered_map::at() method. It will be better to use a more
detailed exception here. It will also fit into design of other
methods from InMemoryStorageBackend.

Change-Id: Ib70f10c79358b08f3b2a792143a1498050cc677a

src/service/storage/InMemoryStorageBackend.cpp

index ab80521..b213111 100644 (file)
@@ -37,8 +37,12 @@ PolicyBucket InMemoryStorageBackend::searchDefaultBucket(const PolicyKey &key) {
 
 PolicyBucket InMemoryStorageBackend::searchBucket(const PolicyBucketId &bucketId,
                                                   const PolicyKey &key) {
-    const auto &bucket = this->buckets().at(bucketId);
-    return bucket.filtered(key);
+    try {
+        const auto &bucket = this->buckets().at(bucketId);
+        return bucket.filtered(key);
+    } catch (const std::out_of_range &) {
+        throw BucketNotExistsException(bucketId);
+    }
 }
 
 void InMemoryStorageBackend::insertPolicy(const PolicyBucketId &bucketId, PolicyPtr policy) {