Skip to content

Commit 80827ee

Browse files
authored
DPL: add test for exception throwing in Variant (#13735)
1 parent 6321af7 commit 80827ee

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Framework/Core/include/Framework/Variant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class Variant
355355
T get() const
356356
{
357357
if (mType != variant_trait_v<T>) {
358-
throw runtime_error("Mismatch between types");
358+
throw runtime_error_f("Variant::get: Mismatch between types %d %d.", mType, variant_trait_v<T>);
359359
}
360360
return variant_helper<T>::get(&mStore);
361361
}

Framework/Core/test/test_Variants.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,15 @@ TEST_CASE("VariantJSONConversionsTest")
338338
REQUIRE(vstrings[i] == vvstra.get<std::string*>()[i]);
339339
}
340340
}
341+
342+
TEST_CASE("VariantThrowing")
343+
{
344+
Variant a("true");
345+
REQUIRE_THROWS_AS(a.get<int>(), o2::framework::RuntimeErrorRef);
346+
try {
347+
a.get<int>();
348+
} catch (RuntimeErrorRef& ref) {
349+
RuntimeError& error = error_from_ref(ref);
350+
REQUIRE(error.what == std::string("Variant::get: Mismatch between types 4 0."));
351+
}
352+
}

0 commit comments

Comments
 (0)