00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef DSC_EXCEPTION_HXX
00028 #define DSC_EXCEPTION_HXX
00029
00030 #include "Utils_SALOME_Exception.hxx"
00031 #include <string>
00032 #include <iostream>
00033 #include <sstream>
00034 #include <memory>
00035
00036 #include "utilities.h"
00037
00038 #ifndef WIN32
00039 extern "C"
00040 {
00041 #endif
00042 #include <string.h>
00043 #ifndef WIN32
00044 }
00045 #endif
00046
00047
00048 #if defined(_DEBUG_) || defined(_DEBUG)
00049 # ifdef __GNUC__
00050 # define LOC(message) (message), __FILE__ , __LINE__ , __FUNCTION__
00051 # else
00052 # define LOC(message) (message), __FILE__, __LINE__
00053 # endif
00054 #else
00055 # define LOC(message) (message)
00056 #endif
00057
00058
00059 #ifndef SWIG
00060
00064 class OSS
00065 {
00066 private:
00067 std::ostringstream oss_;
00068
00069 public:
00070 explicit OSS() : oss_() {}
00071
00072 template <class T>
00073 OSS & operator<<(T obj)
00074 {
00075 oss_ << obj;
00076 return *this;
00077 }
00078
00079 operator std::string()
00080 {
00081 return oss_.str();
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091 };
00092 #endif
00093
00094
00095
00096
00097 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber);
00098
00099 struct DSC_Exception : public SALOME_Exception {
00100
00101
00102
00103
00104
00105
00106
00107
00108 DSC_Exception( const std::string & text,
00109 const char *fileName="",
00110 const unsigned int lineNumber=0,
00111 const char *funcName="" ):
00112 SALOME_Exception(text.c_str()) ,
00113 _dscText(text),
00114 _filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")),
00115 _lineNumber(lineNumber),
00116 _exceptionName("DSC_Exception")
00117 {
00118
00119 delete [] ((char*)SALOME_Exception::_text);
00120 if (! _filefuncName.empty() )
00121 SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ;
00122 else
00123 SALOME_Exception::_text = makeText(text.c_str(),0,lineNumber) ;
00124
00125 OSS oss ;
00126 oss << _exceptionName ;
00127 if (!_filefuncName.empty() ) oss << " in " << _filefuncName;
00128 if (_lineNumber) oss << " [" << _lineNumber << "]";
00129 oss << " : " << _dscText;
00130 _what = oss;
00131 }
00132
00133 virtual const char* what( void ) const throw ()
00134 {
00135 return _what.c_str() ;
00136 }
00137
00138
00139
00140
00141
00142
00143 virtual ~DSC_Exception(void) throw() {};
00144
00145 virtual const std::string & getExceptionName() const {return _exceptionName;};
00146
00147 private:
00148
00149 std::string setFileFuncName(const char * fileName, const char * funcName) {
00150 ASSERT(fileName);
00151 ASSERT(funcName);
00152 OSS oss;
00153 if ( strcmp(fileName,"") )
00154 oss << fileName << "##" << funcName;
00155
00156 return oss;
00157 };
00158
00159
00160 protected:
00161 std::string _dscText;
00162 std::string _filefuncName;
00163 std::string _exceptionName;
00164 int _lineNumber;
00165 std::string _what;
00166 };
00167
00168 #define DSC_EXCEPTION(Derived) struct Derived : public DSC_Exception { \
00169 Derived ( const std::string & text, const char *fileName="", const unsigned int lineNumber=0, const char *funcName="" \
00170 ) : DSC_Exception(text,fileName,lineNumber,funcName) { \
00171 _exceptionName = #Derived; \
00172 } \
00173 virtual ~Derived(void) throw();\
00174 };\
00175
00176
00177
00178
00179 #define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) throw() {};
00180
00181 #endif