C/C++ exception handling and logging library
BSD-3-CLAUSE License
A library to assist in dealing with exceptions and errors in C/C++ Windows Applications
Author: MSDN.WhiteKnight (https://github.com/MSDN-WhiteKnight)
License: BSD 3-clause
Requirements: Windows Vista (or newer), Visual Studio 2010 (or newer)
Notes:
Simple usage example:
#include <stdio.h>
#include "ErrLib.h"
#include "ErrLib_CPP.h"
// Function that throws exception when parameter value is invalid
float CalcRectangleArea(float width, float height){
if(width<=0.0) throw ErrLib::Exception(L"Width must be positive");
if(height<=0.0) throw ErrLib::Exception(L"Height must be positive");
return width * height;
}
void func1(){
float s = CalcRectangleArea(0.0, 2.0);
wprintf(L"%f\n", s);
}
void func(){
try
{
func1();
}
catch(ErrLib::Exception& ex)
{
// Catch exception and print diagnostic information
wprintf(L"Exception: %s\n%s", ex.GetMsg().c_str(), ex.PrintStackTrace().c_str());
}
}
int main()
{
ErrLib_Initialize();
func();
getchar();
return 0;
}
/* Example output:
Exception: Width must be positive
in ErrLib_Demo.exe!CalcRectangleArea + 0x7c (c:\repos\errlib\errlib_demo\main.cpp; line: 10;)
in ErrLib_Demo.exe!func1 + 0x3f (c:\repos\errlib\errlib_demo\main.cpp; line: 17;)
in ErrLib_Demo.exe!func + 0x50 (c:\repos\errlib\errlib_demo\main.cpp; line: 25;)
in ErrLib_Demo.exe!main + 0x28 (c:\repos\errlib\errlib_demo\main.cpp; line: 39;)
in ErrLib_Demo.exe!__tmainCRTStartup + 0x199 (f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c; line: 536;)
in ErrLib_Demo.exe!mainCRTStartup + 0x0d (f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c; line: 377;)
in KERNEL32.DLL!BaseThreadInitThunk (C:\WINDOWS\System32\KERNEL32.DLL; address: 0x7781fa29)
in ntdll.dll!RtlGetAppContainerNamedObjectPath (C:\WINDOWS\SYSTEM32\ntdll.dll; address: 0x77967a9e)
in ntdll.dll!RtlGetAppContainerNamedObjectPath (C:\WINDOWS\SYSTEM32\ntdll.dll; address: 0x77967a6e)
*/
For more code examples, see Examples subdirectory. For a list of functions, see API Documentation.