summaryrefslogtreecommitdiff
path: root/includes/Exceptions.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-03 14:48:05 -0700
committerPixel <pixel@nobis-crew.org>2011-10-03 14:48:05 -0700
commit342b273234405ab76dc159d2e402bfb1ddfa1d8f (patch)
treef10d6857960313d6fc3b0aaa325ed46b8ad481fb /includes/Exceptions.h
First commit - very basic features.
Diffstat (limited to 'includes/Exceptions.h')
-rw-r--r--includes/Exceptions.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/includes/Exceptions.h b/includes/Exceptions.h
new file mode 100644
index 0000000..39f3239
--- /dev/null
+++ b/includes/Exceptions.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <BString.h>
+
+namespace Balau {
+
+class GeneralException {
+ public:
+ GeneralException(const char * msg) : m_msg(::strdup(msg)) { }
+ GeneralException(const String & msg) : m_msg(msg.strdup()) { }
+ GeneralException(const GeneralException & e) : m_msg(strdup(e.m_msg)) { }
+ ~GeneralException() { if (m_msg) free(m_msg); }
+ const char * getMsg() const { return m_msg; }
+
+ protected:
+ GeneralException() : m_msg(0) { }
+ void setMsg(char * msg) { if (m_msg) free(m_msg); m_msg = msg; }
+ private:
+ char * m_msg;
+};
+
+static inline void AssertHelper(const String & msg) throw(GeneralException) { throw GeneralException(msg); }
+
+};
+
+#define Assert(c) if (!(c)) { \
+ Balau::String msg; \
+ msg.set("Assertion " #c " failed at %s:%i", __FILE__, __LINE__); \
+ Balau::AssertHelper(msg); \
+}