From d3fa7fdfea6a0a229f58713e2ee576192245c6e3 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 24 Aug 2023 16:19:49 +0300 Subject: [PATCH] Make ecs::entity_accessor::get throw the documented exception --- libs/ecs/include/psemek/ecs/entity_container.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/ecs/include/psemek/ecs/entity_container.hpp b/libs/ecs/include/psemek/ecs/entity_container.hpp index 04df8620..dc70f6c3 100644 --- a/libs/ecs/include/psemek/ecs/entity_container.hpp +++ b/libs/ecs/include/psemek/ecs/entity_container.hpp @@ -19,10 +19,10 @@ namespace psemek::ecs using query_cache = std::shared_ptr; - struct component_exception + struct component_not_found_exception : util::exception { - component_exception(std::type_info const & type, entity_handle const & handle, boost::stacktrace::stacktrace stacktrace = {}) + component_not_found_exception(std::type_info const & type, entity_handle const & handle, boost::stacktrace::stacktrace stacktrace = {}) : util::exception(util::to_string("Component ", util::type_name(type), " not found for entity ", handle), std::move(stacktrace)) , type_(type) , handle_(handle) @@ -60,7 +60,7 @@ namespace psemek::ecs /** Obtain a reference to the specified component type * of the accessed entity. * If the entity doesn't contain this component type, - * an exception of type `component_exception` is thrown. + * an exception of type `component_not_found_exception` is thrown. */ template Component & get(); @@ -323,8 +323,7 @@ namespace psemek::ecs { if (auto ptr = get_if()) return *ptr; - assert(false); - __builtin_unreachable(); + throw component_not_found_exception(typeid(Component), table_->get_entity_handles()[row_]); } template