diff options
author | Chris Robinson <[email protected]> | 2019-05-04 18:03:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-05-04 18:03:25 -0700 |
commit | 5ff8d5ae32943c5325172799f31b7c5b66c4f054 (patch) | |
tree | 1920073d9a1325f8d203fa187e2a9bf1b7d8b011 /common | |
parent | 1607f9c525eedb4af5b736990fd4e6640f37def0 (diff) |
Add an exception class to cover backend creation and opening
Diffstat (limited to 'common')
-rw-r--r-- | common/alexcpt.cpp | 30 | ||||
-rw-r--r-- | common/alexcpt.h | 18 |
2 files changed, 48 insertions, 0 deletions
diff --git a/common/alexcpt.cpp b/common/alexcpt.cpp new file mode 100644 index 00000000..21508b13 --- /dev/null +++ b/common/alexcpt.cpp @@ -0,0 +1,30 @@ + +#include "config.h" + +#include "alexcpt.h" + +#include <cstdio> +#include <cstdarg> + +#include "opthelpers.h" + + +namespace al { + +backend_exception::backend_exception(ALCenum code, const char *msg, ...) : mErrorCode{code} +{ + va_list args, args2; + va_start(args, msg); + va_copy(args2, args); + int msglen{std::vsnprintf(nullptr, 0, msg, args)}; + if(UNLIKELY(msglen > 0)) + { + mMessage.resize(static_cast<size_t>(msglen)+1); + std::vsnprintf(&mMessage[0], mMessage.length(), msg, args2); + mMessage.pop_back(); + } + va_end(args2); + va_end(args); +} + +} // namespace al diff --git a/common/alexcpt.h b/common/alexcpt.h index 3e31667e..b4f6f55e 100644 --- a/common/alexcpt.h +++ b/common/alexcpt.h @@ -2,7 +2,25 @@ #define ALEXCPT_H #include <exception> +#include <string> +#include "AL/alc.h" + + +namespace al { + +class backend_exception final : public std::exception { + std::string mMessage; + ALCenum mErrorCode; + +public: + backend_exception(ALCenum code, const char *msg, ...); + + const char *what() const noexcept override { return mMessage.c_str(); } + ALCenum errorCode() const noexcept { return mErrorCode; } +}; + +} // namespace al #define START_API_FUNC try |