Constructs an exception object by a specified error code, and an std::basic_string string object. .
- Template Parameters
-
fn_t | is 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. |
char_t | is a type of a symbol of an std::basic_string object specifying the description. |
traits_t | is a type of a character traits class that is used by the std::basic_string template. |
alloc_t | is a type of an allocator class used by the std::basic_string template. |
- Parameters
-
[in] | nCode | is a code to be associated with the constructed exception object. |
[in] | GetDescription | is 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] | strDescriptionFormat | is a string of type that is an instantiation of the std::basic_string template with a type of characters used and the value_type alias given as wchar_t . If the <CODE> or <DESCRIPTION> tags are located within the string, they are replaced by a numeric value of the code and a corresponding description retrieved from a call to the GetDescription function object. To specify angle brackets within the constructed description, use the "<<" and ">>" pairs for a left and a right angle bracket respectively. To disable the described tag-formatting, pass the nullptr value to the second parameter to use the corresponding overload of the constructor. |
There are two predefined tags - <CODE> and <DESCRIPTION> - that are always replaced by a numeric (hexadecimal) value of an error code and to its description, returned by the functor, respectively. To discard this behaviour of the function, use another overload of the ExceptionWithGenericCode function.
- See also
- ExceptionWithGenericCode(code_t nCode, fn_t&& GetDescription, const char_t* restrict lpszDescriptionFormat, DescriptionFormatParams... formatting_params);
ExceptionWithGenericCode(code_t nCode, fn_t&& GetDescription, Exception::vararg_tag_t, _In_opt_z_ const char_t* RESTRICT lpszDescriptionFormat, std::va_list ap);
ExceptionWithGenericCode(code_t nCode, Exception::vararg_tag_t, _In_opt_z_ const char_t* RESTRICT lpszDescriptionFormat, std::va_list ap).