Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

base.Exception.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 Eric NICOLAS
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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         // The exception stream
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 } // namespace sword
00157 
00158 
00159 #include "sword.private/base.Exception.inl"
00160 
00161 #endif // _SWORD_BASE_EXCEPTION_

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2