Implement error-handling (file names and locations) via std::source_location and added CRT debugging memory leak detection.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user