fix case of variant which is valueless by exception (#3347)

Co-authored-by: theomegacarrot <theomegacarrot@gmail.com>
This commit is contained in:
TheOmegaCarrot
2023-03-18 07:07:06 -07:00
committed by GitHub
co-authored by theomegacarrot
parent e1720c0e51
commit d8e1c4265a
2 changed files with 42 additions and 5 deletions
+9 -5
View File
@@ -218,11 +218,15 @@ struct formatter<
auto out = ctx.out();
out = detail::write<Char>(out, "variant(");
std::visit(
[&](const auto& v) {
out = detail::write_variant_alternative<Char>(out, v);
},
value);
try {
std::visit(
[&](const auto& v) {
out = detail::write_variant_alternative<Char>(out, v);
},
value);
} catch (const std::bad_variant_access&) {
detail::write<Char>(out, "valueless by exception");
}
*out++ = ')';
return out;
}