From 9be977b85a40a1e30f1f472f0c2769e8f516bbf5 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Thu, 17 Jul 2014 18:44:28 +0200 Subject: [PATCH] Catch and throw more detailed exception, when bucket not found 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/service/storage/InMemoryStorageBackend.cpp b/src/service/storage/InMemoryStorageBackend.cpp index ab80521..b213111 100644 --- a/src/service/storage/InMemoryStorageBackend.cpp +++ b/src/service/storage/InMemoryStorageBackend.cpp @@ -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) { -- 2.7.4