aboutsummaryrefslogtreecommitdiff
path: root/Exception.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Exception.cpp')
-rw-r--r--Exception.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/Exception.cpp b/Exception.cpp
new file mode 100644
index 0000000..d9765da
--- /dev/null
+++ b/Exception.cpp
@@ -0,0 +1,34 @@
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+
+#include "Exception.h"
+
+Exception::~Exception() {
+ if (error != NULL)
+ free(error);
+}
+
+const char * Exception::what() {
+ return error;
+}
+
+void Exception::va_format(va_list args, const char * fmt) {
+ va_list args_copy;
+ va_copy(args_copy, args);
+
+ size_t sz = vsnprintf(NULL, 0, fmt, args_copy) + 1;
+ if (error != NULL) free(error);
+ error = (char *) malloc(sz);
+ va_end(args_copy);
+
+ vsnprintf(error, sz, fmt, args);
+}
+
+Exception::Exception(const char * fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ va_format(args, fmt);
+ va_end(args);
+}
+