00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _SWORD_BASE_EXCEPTION_
00020 #define _SWORD_BASE_EXCEPTION_
00021
00022 #include <exception>
00023 #include "ace/Synch.h"
00024
00025 namespace sword {
00026
00048 class SWORDDECL Exception : public std::exception {
00049 public:
00051 Exception();
00052
00054 Exception(const std::string &message);
00055
00057 Exception(const char *message);
00058
00059 virtual ~Exception() throw();
00060
00062 virtual const char *what() const throw();
00063
00064 const char *file() const throw();
00065 word line() const throw();
00066
00067 private:
00068 std::string message_;
00069 const char* file_;
00070 word line_;
00071 };
00072
00074
00079 extern SWORDDECL void (*onExceptionHandler)(const std::string& message, const char *file, word line);
00080
00085 class UnimplementedException : public Exception {};
00086
00094 class InternalException : public Exception {};
00095
00096
00097
00098 class SWORDDECL ExceptionStream {
00099 public:
00100 std::ostringstream &stream(const char *file, int line)
00101 {
00102 file_ = file;
00103 line_ = line;
00104 return stream_;
00105 }
00106 void reset()
00107 {
00108 stream_.str("");
00109 }
00110 std::string message()
00111 {
00112 if (stream_.str().empty())
00113 stream_ << "No error description available";
00114 return stream_.str();
00115 }
00116 const char *file() const throw()
00117 {
00118 return file_;
00119 }
00120 word line() const throw()
00121 {
00122 return line_;
00123 }
00124
00125 private:
00126 std::ostringstream stream_;
00127 const char *file_;
00128 int line_;
00129 };
00130
00131 extern SWORDDECL ACE_TSS<ExceptionStream> TheExceptionStream;
00132
00134
00138 #define Assert(cond) \
00139 do { \
00140 if (!(cond)) \
00141 { \
00142 ::sword::TheExceptionStream->stream(__FILE__, __LINE__) << "Assertion Failed : " << #cond; \
00143 throw InternalException(); \
00144 } \
00145 } while(0)
00146
00147 #define Unimplemented() \
00148 do { \
00149 ::sword::TheExceptionStream->stream(__FILE__, __LINE__) << "Unimplemented feature"; \
00150 throw UnimplementedException(); \
00151 } while(0)
00152
00154 #define estream TheExceptionStream->stream(__FILE__, __LINE__)
00155
00156 }
00157
00158
00159 #include "sword.private/base.Exception.inl"
00160
00161 #endif // _SWORD_BASE_EXCEPTION_