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

View File

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