7 #include "arg_router/exception.hpp"
8 #include "arg_router/policy/policy.hpp"
9 #include "arg_router/utility/tuple_iterator.hpp"
11 #include <boost/lexical_cast.hpp>
31 template <
typename TranslationType,
32 typename FallbackTranslationType = default_error_code_translations>
33 class exception_translator_t
36 using get_translations =
typename T::error_code_translations;
39 using get_translations_or_default =
40 boost::mp11::mp_eval_if_c<!traits::has_error_code_translations_type_v<T>,
46 boost::mp11::mp_append<get_translations_or_default<TranslationType>,
47 get_translations_or_default<FallbackTranslationType>>;
55 [[noreturn]]
static void translate_exception(
const multi_lang_exception& e)
57 utility::tuple_type_iterator<translations>([&](
auto i) {
58 using entry_type = std::tuple_element_t<i, translations>;
60 constexpr
auto this_ec = boost::mp11::mp_front<entry_type>::value;
61 using this_msg = boost::mp11::mp_back<entry_type>;
63 if (this_ec == e.ec()) {
64 throw parse_exception{utility::exception_formatter<this_msg>{}, e.tokens()};
68 const auto ec =
static_cast<std::underlying_type_t<error_code>
>(e.ec());
73 throw parse_exception{
"Untranslated error code (" + boost::lexical_cast<string>(ec) +
")",
85 template <
typename TranslationType,
86 typename FallbackTranslationType = default_error_code_translations>
88 exception_translator_t<TranslationType, FallbackTranslationType>{};
90 template <
typename TranslationType,
typename FallbackTranslationType>
91 struct is_policy<exception_translator_t<TranslationType, FallbackTranslationType>> :
constexpr auto exception_translator