ErrLib
|
Go to the source code of this file.
Classes | |
struct | structERRLIB_STACK_FRAME |
struct | structERRLIB_STACK_TRACE |
Macros | |
#define | ErrLib_MessageLen 1024 |
#define | ErrLib_StackLen 10000 |
#define | MSG_ERROR ((DWORD)0xC0020100L) |
#define | MSG_WARNING ((DWORD)0x80020101L) |
#define | MSG_INFORMATION ((DWORD)0x40020102L) |
#define | ERRLIB_OUTPUT_LOGFILE 1 |
#define | ERRLIB_OUTPUT_STDERR 2 |
#define | ERRLIB_OUTPUT_MBOX 3 |
#define | ERRLIB_OUTPUT_EVENT_LOG 4 |
#define | ERRLIB_OUTPUT_CUSTOM 5 |
#define | ERRLIB_SYMBOL_NAME 1 |
#define | ERRLIB_SYMBOL_MODULE 2 |
#define | ERRLIB_SYMBOL_SOURCE 3 |
#define | ERRLIB_THROW(mes) |
#define | ERRLIB_THROW_IF_EQUAL(var, value, func) |
#define | ERRLIB_THROW_IF_FAILED(var, func) |
#define | ERRLIB_INVOKEAPI(func, ...) |
#define | ERRLIB_CATCH_ALL __except(ErrLib_CatchAll(GetExceptionInformation())) |
#define | ERRLIB_CATCH(code) __except(ErrLib_CatchCode(GetExceptionInformation(),code)) |
Typedefs | |
typedef struct structERRLIB_STACK_FRAME | ERRLIB_STACK_FRAME |
typedef struct structERRLIB_STACK_TRACE | ERRLIB_STACK_TRACE |
Functions | |
ERRLIB_API void __stdcall | ErrLib_ErrorMes (LPTSTR lpszFunction, DWORD dw, WCHAR *buf) |
ERRLIB_API void __stdcall | ErrLib_SetLoggingCallback (ERRLIB_LOGGING_CALLBACK pCallback) |
ERRLIB_API void __stdcall | ErrLib_SetExceptionCallback (ERRLIB_EXCEPTION_CALLBACK pCallback) |
ERRLIB_API void __stdcall | ErrLib_SetLogFilePath (LPCWSTR path) |
ERRLIB_API BOOL __stdcall | ErrLib_SetParameter (UINT param, UINT_PTR value) |
BOOL ERRLIB_INLINE | ErrLib_Initialize () |
ERRLIB_API BOOL __stdcall | ErrLib_RegisterEventSource () |
ERRLIB_API BOOL __stdcall | ErrLib_UnregisterEventSource () |
ERRLIB_API ERRLIB_STACK_TRACE __stdcall | ErrLib_GetStackTrace (CONTEXT *ctx) |
ERRLIB_API int __stdcall | ErrLib_ST_GetFramesCount (const ERRLIB_STACK_TRACE *pStack) |
ERRLIB_API const ERRLIB_STACK_FRAME *__stdcall | ErrLib_ST_GetFrame (const ERRLIB_STACK_TRACE *pStack, int n) |
ERRLIB_API uint64_t __stdcall | ErrLib_ST_GetAddress (const ERRLIB_STACK_FRAME *pFrame) |
ERRLIB_API uint64_t __stdcall | ErrLib_ST_GetDisplacement (const ERRLIB_STACK_FRAME *pFrame) |
ERRLIB_API const WCHAR *__stdcall | ErrLib_ST_GetStringProperty (const ERRLIB_STACK_FRAME *pFrame, int propId) |
ERRLIB_API DWORD __stdcall | ErrLib_ST_GetSymLine (const ERRLIB_STACK_FRAME *pFrame) |
ERRLIB_API void __stdcall | ErrLib_FreeStackTrace (ERRLIB_STACK_TRACE *pStack) |
ERRLIB_API void __stdcall | ErrLib_PrintStack (CONTEXT *ctx, WCHAR *dest, size_t cch) |
ERRLIB_API void __stdcall | ErrLib_GetExceptionMessage (struct _EXCEPTION_POINTERS *ExceptionInfo, LPWSTR dest, size_t cch) |
ERRLIB_API void __stdcall | ErrLib_LogExceptionInfo (DWORD dwExcCode, LPCWSTR lpwsMessage, LPCWSTR lpwsStackTrace, BOOL visible) |
ERRLIB_API void __stdcall | ErrLib_LogMessage (LPCWSTR lpwsMessage, BOOL visible, DWORD type, BOOL bIncludeStack) |
ERRLIB_API DWORD __stdcall | ErrLib_Except_GetCode () |
ERRLIB_API LPWSTR __stdcall | ErrLib_Except_GetMessage () |
ERRLIB_API LPWSTR __stdcall | ErrLib_Except_GetStackTrace () |
ERRLIB_API ERRLIB_STACK_TRACE __stdcall | ErrLib_Except_GetStackTraceData () |
ErrLib public API
#define ERRLIB_CATCH | ( | code | ) | __except(ErrLib_CatchCode(GetExceptionInformation(),code)) |
SEH custom _except
block that executes handler for exceptions with specified code
#define ERRLIB_CATCH_ALL __except(ErrLib_CatchAll(GetExceptionInformation())) |
SEH custom _except
block that executes handler for all exceptions
#define ERRLIB_INVOKEAPI | ( | func, | |
... | |||
) |
Calls WINAPI function and raises Win32 exception if it fails. This only works for ones that return BOOL value indicating success/failure.
func | the name of WINAPI function to be called |
This macro is useful to convert a WINAPI function's error code into exception to make it harder to ignore errors.
#define ErrLib_MessageLen 1024 |
Specifies the maximum message length supported by the ErrLib_GetExceptionMessage function
#define ERRLIB_OUTPUT_CUSTOM 5 |
Specifies that logging functions should write information into the custom logging target
#define ERRLIB_OUTPUT_EVENT_LOG 4 |
Specifies that logging functions should write information into Windows Event Log
#define ERRLIB_OUTPUT_LOGFILE 1 |
Specifies that logging functions should write information into the log file
#define ERRLIB_OUTPUT_MBOX 3 |
Specifies that logging functions should display information as a message box
#define ERRLIB_OUTPUT_STDERR 2 |
Specifies that logging functions should write information into the stderr stream
#define ErrLib_StackLen 10000 |
Specifies the maximum stack trace length supported by the ErrLib_PrintStack function
#define ERRLIB_SYMBOL_MODULE 2 |
Stack frame property: Module file path
#define ERRLIB_SYMBOL_NAME 1 |
Stack frame property: Symbol name
#define ERRLIB_SYMBOL_SOURCE 3 |
Stack frame property: Symbol source file path
#define ERRLIB_THROW | ( | mes | ) |
Raises SEH exception with user-defined error message
#define ERRLIB_THROW_IF_EQUAL | ( | var, | |
value, | |||
func | |||
) |
Raises Win32 exception if variable is equal to the passed value
var | Variable to be compared |
value | A value for the variable to be compared against |
func | The name of WINAPI function to be included in error message |
This macro is useful to convert a WINAPI function's error code into exception to make it harder to ignore errors.
#define ERRLIB_THROW_IF_FAILED | ( | var, | |
func | |||
) |
Raises COM exception if passed HRESULT indicates failure
var | HRESULT variable to be tested for failure |
func | The name of WINAPI/COM function to be included in error message |
This macro is useful to convert a WINAPI/COM function's error code into exception to make it harder to ignore errors.
#define MSG_ERROR ((DWORD)0xC0020100L) |
Message type: Error (used with ErrLib_LogMessage)
#define MSG_INFORMATION ((DWORD)0x40020102L) |
Message type: Information (used with ErrLib_LogMessage)
#define MSG_WARNING ((DWORD)0x80020101L) |
Message type: Warning (used with ErrLib_LogMessage)
typedef struct structERRLIB_STACK_FRAME ERRLIB_STACK_FRAME |
Represents a stack frame, an object that contains information about an individual call in stack trace
typedef struct structERRLIB_STACK_TRACE ERRLIB_STACK_TRACE |
Represents a stack trace, a chain of function calls at the particular point of thread's execution
ERRLIB_API void __stdcall ErrLib_ErrorMes | ( | LPTSTR | lpszFunction, |
DWORD | dw, | ||
WCHAR * | buf | ||
) |
Gets Win32 error message for the specified function name and error code. The message depends on the OS locale.
lpszFunction | The name of the function which might have caused the error |
dw | Error code returned by GetLastError() |
buf | Pointer to character array to store the result string |
ERRLIB_API DWORD __stdcall ErrLib_Except_GetCode | ( | ) |
Gets the exception code for the current exception in ERRLIB_CATCH/ERRLIB_CATCH_ALL block
ERRLIB_API LPWSTR __stdcall ErrLib_Except_GetMessage | ( | ) |
Gets the error message for the current exception in ERRLIB_CATCH/ERRLIB_CATCH_ALL block
ERRLIB_API LPWSTR __stdcall ErrLib_Except_GetStackTrace | ( | ) |
Gets the stack trace text for the current exception in ERRLIB_CATCH/ERRLIB_CATCH_ALL block
ERRLIB_API ERRLIB_STACK_TRACE __stdcall ErrLib_Except_GetStackTraceData | ( | ) |
Gets the stack trace information for the current exception in ERRLIB_CATCH/ERRLIB_CATCH_ALL block
ERRLIB_API void __stdcall ErrLib_FreeStackTrace | ( | ERRLIB_STACK_TRACE * | pStack | ) |
Releases resources associated with the specified stack trace structure
pStack | The pointer to a ERRLIB_STACK_TRACE structure |
ERRLIB_API void __stdcall ErrLib_GetExceptionMessage | ( | struct _EXCEPTION_POINTERS * | ExceptionInfo, |
LPWSTR | dest, | ||
size_t | cch | ||
) |
Prints error message for specified exception
ExceptionInfo | A pointer to the exception information structure |
dest | The pointer to the caller-allocated character array that will be filled with error message text on output. Make sure to allocate a large enough block of memory, otherwise the text will be trimmed. The maximum supported message length is indicated by ErrLib_MessageLen constant. |
cch | The maximum amount of characters that can be put into the array pointed by dest parameter |
ERRLIB_API ERRLIB_STACK_TRACE __stdcall ErrLib_GetStackTrace | ( | CONTEXT * | ctx | ) |
Gets the stack trace information for the specified context record
ctx | The pointer to a CONTEXT structure, containing valid context record on input |
BOOL ERRLIB_INLINE ErrLib_Initialize | ( | ) |
Initializes the library. Must be called before any other functionality is used.
ERRLIB_API void __stdcall ErrLib_LogExceptionInfo | ( | DWORD | dwExcCode, |
LPCWSTR | lpwsMessage, | ||
LPCWSTR | lpwsStackTrace, | ||
BOOL | visible | ||
) |
Outputs the exception information into configured log targets
dwExcCode | SEH Exception code. Use ErrLib_Except_GetCode to obtain it in exception handler block. |
lpwsMessage | A pointer to the wide character string containing error message. Use ErrLib_Except_GetMessage to obtain it in exception handler block. |
lpwsStackTrace | A pointer to the wide character string containing stack trace text. Use ErrLib_Except_GetStackTrace to obtain it in exception handler block. |
visible | Pass TRUE if you want to use ERRLIB_OUTPUT_STDERR/ERRLIB_OUTPUT_MBOX logging targets (if they are enabled by configuration flags), FALSE otherwise |
This function outputs information into one or more logging targets, configured using ErrLib_SetParameter function. It only outputs information into the stderr stream and message box if the visible parameter is TRUE (and if respective flags are enabled). By default, the enabled logging targets are log file and stderr stream.
ERRLIB_API void __stdcall ErrLib_LogMessage | ( | LPCWSTR | lpwsMessage, |
BOOL | visible, | ||
DWORD | type, | ||
BOOL | bIncludeStack | ||
) |
Outputs arbitrary string into configured log targets
lpwsMessage | A pointer to the wide character string containing message being written |
visible | Pass TRUE if you want to use ERRLIB_OUTPUT_STDERR/ERRLIB_OUTPUT_MBOX logging targets (if they are enabled by configuration flags), FALSE otherwise |
type | Can be: MSG_ERROR, MSG_WARNING or MSG_INFORMATION |
bIncludeStack | Pass TRUE if you want to include stack trace into the logged information |
This function outputs information into one or more logging targets, configured using ErrLib_SetParameter function. It only outputs information into the stderr stream and message box if the visible parameter is TRUE (and if respective flags are enabled). By default, the enabled logging targets are log file and stderr stream.
ERRLIB_API void __stdcall ErrLib_PrintStack | ( | CONTEXT * | ctx, |
WCHAR * | dest, | ||
size_t | cch | ||
) |
Prints stack trace for the specified context record
ctx | The pointer to a CONTEXT structure, containing valid context record on input. |
dest | The pointer to the caller-allocated character array that will be filled with stack trace text on output. Make sure to allocate a large enough block of memory, otherwise the text will be trimmed. The maximum supported stack trace length is indicated by ErrLib_StackLen constant. |
cch | The maximum amount of characters that can be put into the array pointed by dest parameter |
ERRLIB_API BOOL __stdcall ErrLib_RegisterEventSource | ( | ) |
Creates registry data for Windows Event Log. Requires elevated priveleges.
ERRLIB_API void __stdcall ErrLib_SetExceptionCallback | ( | ERRLIB_EXCEPTION_CALLBACK | pCallback | ) |
Sets current exception callback - the user-defined function which will be called in case of unhandled SEH exception when there's no debugger attahed to the process. Specify NULL to call default callback.
pCallback | The pointer to callback function |
The callback function must be defined as follows: LONG WINAPI MyExceptionCallback (struct _EXCEPTION_POINTERS* ex, LPCWSTR mes, LPCWSTR stack) {...}
The ex parameter of the callback function points to the exception information structure. The mes and stack parameters point to strings containing human-readable error message and stack trace respectively.
Return EXCEPTION_EXECUTE_HANDLER from callback function to execute default handler (in most cases it will crash application, invoking default Windows Error Reporting dialog window). Call exit
function without returning anything, if you want to avoid this behaviour and terminate application normally.
The default callback writes exception information into configured logging targets and then crashes application.
ERRLIB_API void __stdcall ErrLib_SetLogFilePath | ( | LPCWSTR | path | ) |
Sets current log file path. The default is [MyDocuments]\[ExeFileName].log
ERRLIB_API void __stdcall ErrLib_SetLoggingCallback | ( | ERRLIB_LOGGING_CALLBACK | pCallback | ) |
Sets current logging callback - the user-defined function which will be used as a custom logging target
pCallback | The pointer to callback function |
The callback function must be defined as follows: void WINAPI MyLoggingCallback(LPCWSTR pStr, void* pExtraInfo) {...}
The pStr parameter of the callback function points to the logged message. The pExtraInfo parameter is currently unused.
ERRLIB_API BOOL __stdcall ErrLib_SetParameter | ( | UINT | param, |
UINT_PTR | value | ||
) |
Sets a value for the specified configuration parameter
param | Paramater ID |
value | The new value for the parameter being set. Use TRUE/FALSE constants cast to UINT_PTR for boolean parameters. |
The paramater ID can be one of the following values:
ERRLIB_API uint64_t __stdcall ErrLib_ST_GetAddress | ( | const ERRLIB_STACK_FRAME * | pFrame | ) |
Gets the symbol address from the specified stack frame
pFrame | The pointer to a ERRLIB_STACK_FRAME structure |
ERRLIB_API uint64_t __stdcall ErrLib_ST_GetDisplacement | ( | const ERRLIB_STACK_FRAME * | pFrame | ) |
Gets the stack frame displacement from the symbol address (the difference between the instruction pointer value and the starting address of the function)
pFrame | The pointer to a ERRLIB_STACK_FRAME structure |
ERRLIB_API const ERRLIB_STACK_FRAME *__stdcall ErrLib_ST_GetFrame | ( | const ERRLIB_STACK_TRACE * | pStack, |
int | n | ||
) |
Gets the frame with the specified number from a stack trace
pStack | The pointer to a ERRLIB_STACK_TRACE structure |
n | The frame number to get |
ERRLIB_API int __stdcall ErrLib_ST_GetFramesCount | ( | const ERRLIB_STACK_TRACE * | pStack | ) |
Gets the number of stack frames in the specified stack trace
pStack | The pointer to a ERRLIB_STACK_TRACE structure |
ERRLIB_API const WCHAR *__stdcall ErrLib_ST_GetStringProperty | ( | const ERRLIB_STACK_FRAME * | pFrame, |
int | propId | ||
) |
Gets the value of the string property associated with this stack frame
pFrame | The pointer to a ERRLIB_STACK_FRAME structure |
propId | The integer value that identifies the property to get |
ERRLIB_API DWORD __stdcall ErrLib_ST_GetSymLine | ( | const ERRLIB_STACK_FRAME * | pFrame | ) |
Gets the source line number from the specified stack frame
pFrame | The pointer to a ERRLIB_STACK_FRAME structure |
ERRLIB_API BOOL __stdcall ErrLib_UnregisterEventSource | ( | ) |
Deletes Windows Event Log registry data. Requires elevated priveleges.