diff --git a/src/option_manager.cc b/src/option_manager.cc index 817d5409..9471f03c 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -93,8 +93,21 @@ private: Option::Option(OptionManager& manager, String name) : m_manager(manager), m_name(std::move(name)) {} -template const T& Option::get() const { return dynamic_cast*>(this)->get(); } -template void Option::set(const T& val) { return dynamic_cast*>(this)->set(val); } +template const T& Option::get() const +{ + auto* typed_opt = dynamic_cast*>(this); + if (not typed_opt) + throw runtime_error("option " + name() + " is not of type " + typeid(T).name()); + return typed_opt->get(); +} + +template void Option::set(const T& val) +{ + auto* typed_opt = dynamic_cast*>(this); + if (not typed_opt) + throw runtime_error("option " + name() + " is not of type " + typeid(T).name()); + return typed_opt->set(val); +} template const String& Option::get() const; template void Option::set(const String&);