chsvlib
chsv helper source code

◆ ExceptionWithGenericCode() [3/10]

ExceptionWithGenericCode ( code_t  nCode,
fn_t &&  GetDescription,
const char_t *restrict  lpszDescriptionFormat,
DescriptionFormatParams ...  formatting_params 
)
noexcept

Constructs an exception object by a specified error code, a functor, mapping the code to a description text, a format string and parameters for the formatting as specified by the Chusov::String::Printf function. .

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 code to be associated with the constructed exception object.
[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]lpszDescriptionFormatis an optional pointer to a string specifying a format of the constructed description. See the details.
[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 constructor creates an instance of the ExceptionWithGenericCode<code_t> class with associated error code and the description. The description is constructed as specified by the format string using control character sequences, as specified for the Chusov::String::Printf <char_t> function. The result of this formatting is analyzed for presence of the <CODE> and <DESCRIPTION> tags which are replaced by a string representation of an error code and by the corresponding description, which is defined by the functor, respectively.

See also
ExceptionWithGenericCode(code_t nCode, const char_t* restrict lpszDescriptionFormat, DescriptionFormatParams... formatting_params);
ExceptionWithGenericCode(code_t nCode, std::va_list ap, const char_t* restrict lpszDescriptionFormat);
ExceptionWithGenericCode(code_t nCode, fn_t&& GetDescription, std::va_list ap, const char_t* restrict lpszDescriptionFormat).