From 342b273234405ab76dc159d2e402bfb1ddfa1d8f Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 3 Oct 2011 14:48:05 -0700 Subject: First commit - very basic features. --- includes/Exceptions.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 includes/Exceptions.h (limited to 'includes/Exceptions.h') 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 + +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); \ +} -- cgit v1.2.3