chsvlib
chsv helper source code

◆ ChsvExceptionByWindowsCode() [2/4]

void Chusov::Exceptions::ChsvExceptionByWindowsCode ( unsigned long  nCode)

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

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

The function generates an exception of a type implemented by either an instantiation of the ChsvCodeExceptionTempl class template or by an instantiation of the PlatformException class template, which directly inherits the ChsvCodeExceptionTempl<CHSVERROR_PLATFORM_ERROR> class. The specific class is determined based on the specified Windows error, or, more specifically, on a result of mapping the Windows error to the corresponding chsvlib error code, which is performed by the 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 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 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 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 what or 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 and its description, retrieved by an internal call to the FormatMessage function.