aboutsummaryrefslogtreecommitdiffstats
path: root/common/alexcpt.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-05-04 18:03:25 -0700
committerChris Robinson <[email protected]>2019-05-04 18:03:25 -0700
commit5ff8d5ae32943c5325172799f31b7c5b66c4f054 (patch)
tree1920073d9a1325f8d203fa187e2a9bf1b7d8b011 /common/alexcpt.cpp
parent1607f9c525eedb4af5b736990fd4e6640f37def0 (diff)
Add an exception class to cover backend creation and opening
Diffstat (limited to 'common/alexcpt.cpp')
-rw-r--r--common/alexcpt.cpp30
1 files changed, 30 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