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

Co-authored-by: theomegacarrot <theomegacarrot@gmail.com>
This commit is contained in:
TheOmegaCarrotandtheomegacarrot authored and GitHub committed 2023-03-18 07:07:06 -07:00
1 parent e1720c0e51
commit d8e1c4265a
2 files changed
+42 -5

No files matched your search

+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;
}