Implement error-handling (file names and locations) via std::source_location and added CRT debugging memory leak detection.

This commit is contained in:
2023-11-11 00:54:50 -06:00
parent 75159a21be
commit 67a5288984
32 changed files with 173 additions and 124 deletions
+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include <ostream>
#ifndef __EMSCRIPTEN__
#include <source_location>
#endif
#ifdef _DEBUG
#define NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
// Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the
// allocations to be of _CLIENT_BLOCK type
#else
#define NEW new
#endif
#undef ERR //Stupid Windows
#ifndef __EMSCRIPTEN__
#define ERR(err) { \
std::stringstream errStream; \
errStream<<err; \
Error::log(errStream,std::source_location::current());}
class Error{
public:
inline static void log(std::stringstream&str,std::source_location loc){
std::cout<<loc.file_name()<<"("<<loc.line()<<":"<<loc.column()<<") "<<loc.function_name()<<": "<<str.str()<<std::endl;
throw;
}
};
#else
#define ERR(err) { \
std::stringstream errStream; \
errStream<<err; \
std::cout<<errStream.str(); }
#define _CrtDumpMemoryLeaks() ((int)0)
#endif