diff --git a/include/core/utils/converter.h b/include/core/utils/converter.h index 49f003633c42e4e5b6dc051e2c0c2c0c560b14b3..ffb955d456f515aa0871a54eea4de84df94af187 100644 --- a/include/core/utils/converter.h +++ b/include/core/utils/converter.h @@ -97,7 +97,7 @@ namespace wolf{ template<typename T> struct converter{ static T convert(std::string val){ - assert(1 == 0 && "There is no general convert for arbitrary T !!!"); + throw std::runtime_error("There is no general convert for arbitrary T !!! String provided: "+ val); } }; template<typename A> @@ -160,8 +160,7 @@ struct converter<std::string>{ } template<typename T> static std::string convert(T val){ - assert(1 == 0 && "There is no general convert to string for arbitrary T !!!"); - return ""; + throw std::runtime_error("There is no general convert to string for arbitrary T !!! String provided: " + val); } static std::string convert(int val){ return std::to_string(val); diff --git a/test/gtest_converter.cpp b/test/gtest_converter.cpp index 6a263e55e7bdb16bfba9a1ab9c275c136e269344..d8378df4616f90af772fe967e06ba892ecb516b5 100644 --- a/test/gtest_converter.cpp +++ b/test/gtest_converter.cpp @@ -49,7 +49,11 @@ TEST(Converter, ParseToMap) map<string, vector<int>> m = {{"x",vector<int>{1,2}}, {"y",vector<int>{}}, {"z",vector<int>{3}}}; ASSERT_EQ(converter<string>::convert(m), "[{x:[1,2]},{y:[]},{z:[3]}]"); } - +TEST(Converter, noGeneralConvert) +{ + class DUMMY{}; + EXPECT_THROW(([=]{converter<DUMMY>::convert("Should fail");}()), std::runtime_error); +} int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv);