diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/alexcpt.cpp | 6 | ||||
-rw-r--r-- | common/alexcpt.h | 18 |
2 files changed, 10 insertions, 14 deletions
diff --git a/common/alexcpt.cpp b/common/alexcpt.cpp index 5055e34f..111258a0 100644 --- a/common/alexcpt.cpp +++ b/common/alexcpt.cpp @@ -11,10 +11,9 @@ namespace al { -backend_exception::backend_exception(ALCenum code, const char *msg, ...) : mErrorCode{code} +void base_exception::setMessage(const char* msg, std::va_list args) { - va_list args, args2; - va_start(args, msg); + std::va_list args2; va_copy(args2, args); int msglen{std::vsnprintf(nullptr, 0, msg, args)}; if LIKELY(msglen > 0) @@ -24,7 +23,6 @@ backend_exception::backend_exception(ALCenum code, const char *msg, ...) : mErro mMessage.pop_back(); } va_end(args2); - va_end(args); } } // namespace al diff --git a/common/alexcpt.h b/common/alexcpt.h index ff09bab2..b399e8f7 100644 --- a/common/alexcpt.h +++ b/common/alexcpt.h @@ -1,28 +1,26 @@ #ifndef ALEXCPT_H #define ALEXCPT_H +#include <cstdarg> #include <exception> #include <string> +#include <utility> #include "AL/alc.h" -#ifdef __GNUC__ -#define ALEXCPT_FORMAT(x, y, z) __attribute__((format(x, (y), (z)))) -#else -#define ALEXCPT_FORMAT(x, y, z) -#endif - - namespace al { -class backend_exception final : public std::exception { +class base_exception : public std::exception { std::string mMessage; ALCenum mErrorCode; -public: - backend_exception(ALCenum code, const char *msg, ...) ALEXCPT_FORMAT(printf, 3,4); +protected: + base_exception(ALCenum code) : mErrorCode{code} { } + void setMessage(const char *msg, std::va_list args); + +public: const char *what() const noexcept override { return mMessage.c_str(); } ALCenum errorCode() const noexcept { return mErrorCode; } }; |