From 0b71f14136ae271577d913804f38f9f4420a48ca Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Sat, 21 Apr 2018 14:12:55 +0300 Subject: [PATCH] Throw an exception if a shared region is not found --- include/storage/shared_data_index.hpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/include/storage/shared_data_index.hpp b/include/storage/shared_data_index.hpp index 0c6bd7942..94f78182a 100644 --- a/include/storage/shared_data_index.hpp +++ b/include/storage/shared_data_index.hpp @@ -46,33 +46,39 @@ class SharedDataIndex template auto GetBlockPtr(const std::string &name) const { - const auto index_iter = block_to_region.find(name); - const auto ®ion = regions[index_iter->second]; + const auto ®ion = GetBlockRegion(name); return region.layout.GetBlockPtr(region.memory_ptr, name); } template auto GetBlockPtr(const std::string &name) { - const auto index_iter = block_to_region.find(name); - const auto ®ion = regions[index_iter->second]; + const auto ®ion = GetBlockRegion(name); return region.layout.GetBlockPtr(region.memory_ptr, name); } std::size_t GetBlockEntries(const std::string &name) const { - const auto index_iter = block_to_region.find(name); - const auto ®ion = regions[index_iter->second]; + const auto ®ion = GetBlockRegion(name); return region.layout.GetBlockEntries(name); } std::size_t GetBlockSize(const std::string &name) const { - const auto index_iter = block_to_region.find(name); - const auto ®ion = regions[index_iter->second]; + const auto ®ion = GetBlockRegion(name); return region.layout.GetBlockSize(name); } private: + const AllocatedRegion &GetBlockRegion(const std::string &name) const + { + const auto index_iter = block_to_region.find(name); + if (index_iter == block_to_region.end()) + { + throw util::exception("data block " + name + " not found " + SOURCE_REF); + } + return regions[index_iter->second]; + } + std::vector regions; std::unordered_map block_to_region; };