Rework how the C Interface shows exceptions
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
418d811d18
commit
9ec41fdd2d
|
@ -1,4 +1,3 @@
|
|||
#include "Core.hpp"
|
||||
|
||||
char* ExceptionHandler::_lastException = 0;
|
||||
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
||||
|
|
|
@ -3,17 +3,23 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#define export extern "C" [[maybe_unused]]
|
||||
|
||||
#define CreatureLibException 1;
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
class ExceptionHandler {
|
||||
static char* _lastException;
|
||||
static std::string _lastException;
|
||||
|
||||
public:
|
||||
static void SetLastException(const std::exception& e) { _lastException = strcpy(_lastException, e.what()); }
|
||||
static const char* GetLastException() { return _lastException; }
|
||||
static void SetLastException(std::string file, std::string function, int line, const std::exception& e) {
|
||||
std::stringstream ss;
|
||||
ss << "[" << file << ", " << function << "-" << line << "] " << e.what();
|
||||
_lastException = ss.str();
|
||||
}
|
||||
static const char* GetLastException() { return _lastException.c_str(); }
|
||||
};
|
||||
|
||||
#define Try(data) \
|
||||
|
@ -21,7 +27,7 @@ public:
|
|||
data; \
|
||||
return 0; \
|
||||
} catch (const std::exception& e) { \
|
||||
ExceptionHandler::SetLastException(e); \
|
||||
ExceptionHandler::SetLastException(__FILENAME__, __FUNCTION__, __LINE__, e); \
|
||||
return CreatureLibException; \
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue