chsvlib
chsv helper source code

◆ SetCodeAndDescription() [5/8]

auto SetCodeAndDescription ( code_t  nCode,
fn_t &&  GetDescription,
const String::TAG_DESCRIPTION_PARAM< char_t > *restrict  pTags,
std::size_t  cTags,
const char_t *restrict  lpszDescriptionFormat,
DescriptionFormatParams ...  formatting_params 
) -> std::enable_if_t<std::is_integral<char_t>::value && Chusov::String::is_valid_printf_type_set_v<DescriptionFormatParams...>, decltype(void(std::declval<fn_t&&>()(std::declval<code_t>())))>
protectednoexcept

Sets a new exception description, according to the specified error code, formatting rules (with custom tags), formatting parameter pack and a functor object mapping the error code to its default string description. .

Template Parameters
char_tis a type of the description to be set which is either char or wchar_t.
fn_tis a type of the function object. A class defining the type must specify public operator() that receives a numeric value of an error code and returns its description which is either a C pointer or an std::unique_ptr pointer to a multibyte or wide C string or and std::basic_string object specialized for char or wchar_t elements and for any CharTraits and Allocator. On failure within the operator the latter may return a NULL, default constructed std::unique_ptr or default constructed std::basic_string object, depending on the return value of the parenthesis operator. In case of the failure the description is constructed from the string saying that the description is not specified.
DescriptionFormatParamsDeduced types of additional arguments passed to the function to format the message.
Parameters
[in]nCodeis a numeric value of the error code.
[in]GetDescriptionis a universal reference to a function object of the fn_t type. It should map the error code to the corresponding string description. The class of the functor must define a parenthesis operator (operator()), which receives an error code as its only parameter and returns a corresponding string. The string can be represented as a C string, either multibyte or wide, as a unique pointer (see std::unique_ptr) to a multibyte or wide string, or as a std::basic_string object specialized for char or wchar_t character type (for multibyte and wide strings respectively) as well as any CharTraits and Allocator. Note, that every type of the strings returned by the operator is considered non-modifiable, so that C strings are not automatically deallocated. On failure the function may return default values of the respected types, that are NULL pointers for C strings, default-constructed std::unique_ptr or default-constructed std::basic_string.
[in]pTagsis an optional pointer to a vector of Chusov::String::TAG_DESCRIPTION_PARAM <char_t> objects specifying additional tags for the formatted description as specified for the Chusov::String::AllocateAndFormatStringByTagsIndirect <char_t> function. The predefined tags are <CODE> and <DESCRIPTION>. If either of these predefined tags are specified by the parameter, the user-defined variants are ignored by the function. See the details.
cTagsis a number of elements specified by the pTags vector. If the latter is NULL, the cTags parameter is ignored.
[in]lpszDescriptionFormatis an optional pointer to a string specifying a format of the constructed description.
[in]formatting_paramsAdditional parameters to be used during the construction of the description, as specified for the Chusov::String::Printf <char_t> function. If lpszDescriptionFormat is NULL, the parameter list is ignored.

The function performs formatting of the output string using control character sequences specified for the Chusov::String::Printf <char_t> function. The result is passed as an input for the formatting by tags (in angle brackets) as specified by the Chusov::String::AllocateAndFormatStringByTags <char_t> function. There are two predefined tags - <CODE> and <DESCRIPTION> - that are always changed to a numeric (hexadecimal) value of an error code and to its description, returned by the functor, respectively. This behaviour cannot be changed by a caller. Other tags may or may not be specified by the pTags pointer to a vector of cTags size. The content of the vector is specified by the documentation to the Chusov::String::AllocateAndFormatStringByTagsIndirect <char_t> function.

After these two transformations, the resulting string becomes a message associated with the exception object and obtained using Exception::what or Exception::What.