More reworks of exceptions.

This commit is contained in:
Deukhoofd 2020-07-26 17:29:06 +02:00
parent 9ec41fdd2d
commit 29eb7c603a
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 5 additions and 4 deletions

View File

@ -14,9 +14,9 @@ class ExceptionHandler {
static std::string _lastException;
public:
static void SetLastException(std::string file, std::string function, int line, const std::exception& e) {
static void SetLastException(std::string function, const std::exception& e) {
std::stringstream ss;
ss << "[" << file << ", " << function << "-" << line << "] " << e.what();
ss << "[" << function << "] " << e.what();
_lastException = ss.str();
}
static const char* GetLastException() { return _lastException.c_str(); }
@ -27,7 +27,7 @@ public:
data; \
return 0; \
} catch (const std::exception& e) { \
ExceptionHandler::SetLastException(__FILENAME__, __FUNCTION__, __LINE__, e); \
ExceptionHandler::SetLastException(__FUNCTION__, e); \
return CreatureLibException; \
}

View File

@ -3,6 +3,7 @@
#include <stdexcept>
#include <string>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
class CreatureException : public std::runtime_error {
public:
@ -12,6 +13,6 @@ public:
#define THROW_CREATURE(message) \
std::stringstream ss; \
ss << message; \
ss << "[" << __FILENAME__ << ", " << __LINE__ << "] " << message; \
throw CreatureException(ss.str());
#endif // CREATURELIB_CREATUREEXCEPTION_HPP