chsvlib
chsv helper source code

◆ ChsvExceptionByWin32Code() [2/4]

void Chusov::Win32::Exceptions::ChsvExceptionByWin32Code ( DWORD  nCode)

Creates an instance of the Chusov::Exceptions::ChsvCodeExceptionTempl class and throws it as an exception. The instantiation of the Chusov::Exceptions::ChsvCodeExceptionTempl class template is chosen depending on the result of a translation of the Windows error code to the corresponding chsvlib error code.

Template Parameters
fProcessSuccessCodeAsUnknownErroris a flag specifying if ERROR_SUCCESS should be interpreted as an unknown error. This means, that if the flag is set, and the error code has a value of ERROR_SUCCESS (or NO_ERROR), then the thrown exception is Chusov::Exceptions::UnknownException. Otherwise, it is ChsvCodeExceptionTempl<CHSVERROR_SUCCESS>.
Parameters
[in]nCodeis Windows error code. The function calls the Windows FormatMessage function when trying matching the code with the corresponding textual description.

The function generates an exception of a type implemented by either an instantiation of the Chusov::Exceptions::ChsvCodeExceptionTempl class template or by an instantiation of the Chusov::Exceptions::PlatformException class template, which directly inherits the Chusov::Exceptions::ChsvCodeExceptionTempl <CHSVERROR_PLATFORM_ERROR> class. The specific class is determined based on the value of Windows error code, or, more specifically, on a result of mapping the value to the corresponding chsvlib error code, which is performed by the Chusov::Win32ErrorToChsvError function. The latter returns CHSVERROR_PLATFORM_ERROR, if the accordance between the Windows error code and a chsvlib error code is not known. In this case the corresponding exception to be thrown is an instance of the Chusov::Exceptions::PlatformException class.

If the mapping to a specific chsvlib error code, which is not CHSVERROR_PLATFORM_ERROR, was performed, the function generates exception of type, which is one of the predefined exceptions, which are instances of the Chusov::Exceptions::ChsvCodeExceptionTempl class template for each specific error code. Such exception will have the default description.

If the mapping to a specific chsvlib error code cannot be performed, the generated exception is of type described by an instantiation of the Chusov::Exceptions::PlatformException class template with DWORD type passed as a template parameter. The description of such an exception, which can later be retrieved by the caller invoking the Chusov::Exceptions::Exception::what or Chusov::Exceptions::Exception::What methods, is:

Windows error <PLATFORM_CODE> ("<PLATFORM_DESCRIPTION>"),

where <PLATFORM_CODE> and <PLATFORM_DESCRIPTION> are tags replaced by a numeric value of the Windows error code and its description, retrieved by an internal call to the FormatMessage function.