Constructs an exception object by a specified error code and a functor, mapping the code to a textual description.
- 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. |
- 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. |
The constructor creates an instance of the ExceptionWithGenericCode<code_t>
class with an associated error code and the description. The description is a string constructed from a value returned by the specified function object, which is either multibyte or wide C string, or corresponding std::basic_string instantiation, or std::unique_ptr pointer to the C string. The returned value is considered constant, so if a pointer to a C string is returned, memory which it points to is not deallocated automatically.
- See also
- ExceptionWithGenericCode(code_t nCode, fn_t&& GetDescription, const char_t* restrict lpszDescriptionFormat, DescriptionFormatParams... formatting_params);
ExceptionWithGenericCode(code_t nCode, const char_t* restrict lpszDescriptionFormat, DescriptionFormatParams... formatting_params);
ExceptionWithGenericCode(code_t nCode).