Rework exceptions.
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-15 16:34:52 +02:00
parent c921d3127b
commit 93a763ab78
12 changed files with 29 additions and 55 deletions

View File

@@ -3,3 +3,4 @@
std::string ExceptionHandler::_creatureLibLastException = "";
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
export const char* CreatureLib_C_GetLastExceptionStacktrace() { return ExceptionHandler::GetLastExceptionStacktrace(); }

View File

@@ -13,20 +13,23 @@
class ExceptionHandler {
static std::string _creatureLibLastException;
static std::string _creatureLibLastExceptionStacktrace;
public:
static void SetLastException(std::string function, const ArbUt::Exception& e) {
static void SetLastArbUtException(const std::string& function, const ArbUt::Exception& e) {
std::stringstream ss;
ss << "[" << function << "] " << e.what() << std::endl;
ss << e.GetStacktrace();
_creatureLibLastException = ss.str();
_creatureLibLastExceptionStacktrace = e.GetStacktrace();
}
static void SetLastException(std::string function, const std::exception& e) {
static void SetLastException(const std::string& function, const std::exception& e) {
std::stringstream ss;
ss << "[" << function << "] " << e.what();
_creatureLibLastException = ss.str();
_creatureLibLastExceptionStacktrace = "";
}
static const char* GetLastException() { return _creatureLibLastException.c_str(); }
static const char* GetLastExceptionStacktrace() { return _creatureLibLastExceptionStacktrace.c_str(); }
};
#define Try(data) \
@@ -34,7 +37,7 @@ public:
data; \
return 0; \
} catch (const ArbUt::Exception& e) { \
ExceptionHandler::SetLastException(__FUNCTION__, e); \
ExceptionHandler::SetLastArbUtException(__FUNCTION__, e); \
return CreatureLibException; \
} catch (const std::exception& e) { \
ExceptionHandler::SetLastException(__FUNCTION__, e); \