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"
|
#include "Core.hpp"
|
||||||
|
|
||||||
char* ExceptionHandler::_lastException = 0;
|
|
||||||
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
||||||
|
|
|
@ -3,17 +3,23 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#define export extern "C" [[maybe_unused]]
|
#define export extern "C" [[maybe_unused]]
|
||||||
|
|
||||||
#define CreatureLibException 1;
|
#define CreatureLibException 1;
|
||||||
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||||
|
|
||||||
class ExceptionHandler {
|
class ExceptionHandler {
|
||||||
static char* _lastException;
|
static std::string _lastException;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void SetLastException(const std::exception& e) { _lastException = strcpy(_lastException, e.what()); }
|
static void SetLastException(std::string file, std::string function, int line, const std::exception& e) {
|
||||||
static const char* GetLastException() { return _lastException; }
|
std::stringstream ss;
|
||||||
|
ss << "[" << file << ", " << function << "-" << line << "] " << e.what();
|
||||||
|
_lastException = ss.str();
|
||||||
|
}
|
||||||
|
static const char* GetLastException() { return _lastException.c_str(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define Try(data) \
|
#define Try(data) \
|
||||||
|
@ -21,7 +27,7 @@ public:
|
||||||
data; \
|
data; \
|
||||||
return 0; \
|
return 0; \
|
||||||
} catch (const std::exception& e) { \
|
} catch (const std::exception& e) { \
|
||||||
ExceptionHandler::SetLastException(e); \
|
ExceptionHandler::SetLastException(__FILENAME__, __FUNCTION__, __LINE__, e); \
|
||||||
return CreatureLibException; \
|
return CreatureLibException; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue