RaiseFailure function
Synopsis
#include <windows.h>
BOOL WINAPI RaiseFailure(
_In_ DWORD dwErrorCode
);
Parameters
Name | Type | Description |
---|---|---|
dwErrorCode | DWORD | Specifies the error code that the function will raise. |
Return value
Returns TRUE
if the error was successfully raised; otherwise returns FALSE
. To retrieve extended error information, call GetLastError.
Remarks
- The function posts a custom error to the calling thread's error queue, emulating a system failure for testing purposes.
- It is intended for diagnostic and debugging scenarios only; it must not be used in production code.
- When
dwErrorCode
is zero, the function raisesERROR_SUCCESS
. - Requires the calling process to have the
SE_DEBUG_NAME
privilege.
Example
#include <windows.h>
#include <iostream>
int main()
{
if (!RaiseFailure(ERROR_ACCESS_DENIED))
{
DWORD err = GetLastError();
std::cerr << "RaiseFailure failed, error: " << err << std::endl;
return 1;
}
std::cout << "Custom error raised successfully." << std::endl;
return 0;
}