00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __PION_PIONEXCEPTION_HEADER__
00011 #define __PION_PIONEXCEPTION_HEADER__
00012
00013 #include <pion/PionConfig.hpp>
00014 #include <exception>
00015 #include <string>
00016 #include <cstdio>
00017
00018
00019 namespace pion {
00020
00024 class PionException :
00025 public std::exception
00026 {
00027 public:
00028
00029 virtual ~PionException() throw () {}
00030
00031
00032 PionException(const char *what_msg) : m_what_msg(what_msg) {}
00033 PionException(const std::string& what_msg) : m_what_msg(what_msg) {}
00034
00035
00036 PionException(const char *description, const std::string& param)
00037 : m_what_msg(std::string(description) + param) {}
00038 PionException(std::string description, const std::string& param)
00039 : m_what_msg(description + param) {}
00040
00042 virtual const char* what() const throw() {
00043 return m_what_msg.c_str();
00044 }
00045
00046 private:
00047
00048
00049 const std::string m_what_msg;
00050 };
00051
00052
00056 class BadAssertException : public PionException {
00057 public:
00058 BadAssertException(const std::string& file, unsigned long line)
00059 : PionException(make_string(file, line)) {}
00060
00061 private:
00062 static std::string make_string(const std::string& file, unsigned long line) {
00063 std::string result("Assertion failed at ");
00064 result += file;
00065 char line_buf[50];
00066 sprintf(line_buf, " line %lu", line);
00067 result += line_buf;
00068 return result;
00069 }
00070 };
00071
00072 }
00073
00074
00075
00076 #ifdef NDEBUG
00077 #define PION_ASSERT(EXPR) ((void)0);
00078 #else
00079 #define PION_ASSERT(EXPR) if (!(EXPR)) { throw BadAssertException(__FILE__, __LINE__); }
00080 #endif
00081
00082
00083 #endif