Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Framework/Core/include/Framework/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class Variant
T get() const
{
if (mType != variant_trait_v<T>) {
throw runtime_error("Mismatch between types");
throw runtime_error_f("Variant::get: Mismatch between types %d %d.", mType, variant_trait_v<T>);
}
return variant_helper<T>::get(&mStore);
}
Expand Down
12 changes: 12 additions & 0 deletions Framework/Core/test/test_Variants.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,15 @@ TEST_CASE("VariantJSONConversionsTest")
REQUIRE(vstrings[i] == vvstra.get<std::string*>()[i]);
}
}

TEST_CASE("VariantThrowing")
{
Variant a("true");
REQUIRE_THROWS_AS(a.get<int>(), o2::framework::RuntimeErrorRef);
try {
a.get<int>();
} catch (RuntimeErrorRef& ref) {
RuntimeError& error = error_from_ref(ref);
REQUIRE(error.what == std::string("Variant::get: Mismatch between types 4 0."));
}
}