LAMA
|
00001 00034 #ifndef LAMA_EXCEPTION_HPP_ 00035 #define LAMA_EXCEPTION_HPP_ 00036 00037 // for dll_import 00038 #include <lama/config.hpp> 00039 00040 // logging 00041 #include <logging/logging.hpp> 00042 00043 #include <exception> 00044 #include <string> 00045 00049 namespace lama 00050 { 00051 00055 class LAMA_DLL_IMPORTEXPORT Exception : public std::exception 00056 { 00057 public: 00058 00059 enum UnsupportedType 00060 { 00061 UNSUPPORTED_WARN, 00062 UNSUPPORTED_ERROR, 00063 UNSUPPORTED_IGNORE, 00064 UNSUPPORTED_UNDEFINED 00065 }; 00066 00072 static void addCallStack( std::ostringstream& output ); 00073 00077 Exception(); 00083 Exception( const std::string& message ); 00087 virtual ~Exception() throw(); 00093 virtual const char* what() const throw(); 00094 00099 static UnsupportedType getUnsupportedSetting(); 00100 00101 protected: 00102 00103 std::string mMessage; 00104 00105 LAMA_LOG_DECL_STATIC_LOGGER( logger ); 00106 00107 private: 00108 00109 static std::string demangle( const char* string ); 00110 00111 static UnsupportedType unsupportedSetting; 00112 }; 00113 00114 } //namespace lama 00115 00116 #define LAMA_THROWEXCEPTION( msg ) \ 00117 { \ 00118 std::ostringstream errorStr; \ 00119 errorStr<<"Exception in line "<<__LINE__<<" of file "<<__FILE__<<"\n"; \ 00120 errorStr<<" Message: "<<msg<<"\n"; \ 00121 lama::Exception::addCallStack( errorStr ); \ 00122 throw lama::Exception( errorStr.str() ); \ 00123 } 00124 00134 #define LAMA_UNSUPPORTED( msg ) \ 00135 { \ 00136 if ( lama::Exception::getUnsupportedSetting() != \ 00137 lama::Exception::UNSUPPORTED_IGNORE ) \ 00138 { \ 00139 std::ostringstream errorStr; \ 00140 errorStr << "Unsupported at line "; \ 00141 errorStr << __LINE__ << " of file " << __FILE__ << "\n"; \ 00142 errorStr << " Message: " << msg << std::endl; \ 00143 errorStr << "Use environenment variable LAMA_UNSUPPORTED"; \ 00144 errorStr << " (WARN or IGNORE) to get rid of this message"; \ 00145 errorStr << std::endl; \ 00146 if ( lama::Exception::getUnsupportedSetting() == \ 00147 lama::Exception::UNSUPPORTED_ERROR ) \ 00148 { \ 00149 throw lama::Exception( errorStr.str() ); \ 00150 } \ 00151 else \ 00152 { \ 00153 std::cout << errorStr.str() << std::endl; \ 00154 } \ 00155 } \ 00156 } 00157 00158 #endif // LAMA_EXCEPTION_HPP_