40 #include <boost/lexical_cast.hpp>
41 #include <boost/optional.hpp>
59 return outStream ?
true :
false;
71 NekError(
const std::string& message) :
std::runtime_error(message) {}
74 inline static void Error(
ErrType type,
const char *routine,
int lineNumber,
const char *msg,
unsigned int level)
81 std::string baseMsg = std::string(
"Level ") +
82 boost::lexical_cast<std::string>(level) +
83 std::string(
" assertion violation\n") +
84 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
85 std::string(
"Where : ") + boost::lexical_cast<std::string>(routine) + std::string(
"[") + boost::lexical_cast<std::string>(lineNumber) + std::string(
"]\n") + std::string(
"Message : ") +
89 std::string btMessage(
"");
90 #if defined(NEKTAR_FULLDEBUG)
96 btSize = backtrace(btArray, 40);
97 btStrings = backtrace_symbols(btArray, btSize);
99 for (
int i = 0 ; i < btSize ; ++i)
101 btMessage += std::string(btStrings[i]) +
"\n";
111 (*outStream) << btMessage;
112 (*outStream) <<
"Fatal : " << baseMsg << std::endl;
116 std::cerr << btMessage;
117 std::cerr << std::endl <<
"Fatal : " << baseMsg << std::endl;
126 (*outStream) << btMessage;
127 (*outStream) <<
"Warning: " << baseMsg << std::endl;
131 std::cerr << btMessage;
132 std::cerr <<
"Warning: " << baseMsg << std::endl;
137 std::cerr <<
"Unknown warning type: " << baseMsg << std::endl;
141 inline static void Error(
ErrType type,
const char *routine,
int lineNumber,
const std::string& msg,
unsigned int level)
143 Error(type, routine, lineNumber, msg.c_str(), level);
146 inline static void Error(
ErrType type,
const char *routine,
int lineNumber,
const char *msg)
148 Error(type, routine, lineNumber, msg, 0);
158 #define NEKERROR(type, msg) \
159 ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0);
161 #define ASSERTL0(condition,msg) \
164 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 0); \
167 #define WARNINGL0(condition,msg) \
170 ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 0); \
177 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
179 #define ASSERTL1(condition,msg) \
182 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 1); \
184 #define WARNINGL1(condition,msg) \
187 ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 0); \
190 #else //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
191 #define ASSERTL1(condition,msg)
192 #define WARNINGL1(condition,msg)
193 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
199 #ifdef NEKTAR_FULLDEBUG
201 #define ASSERTL2(condition,msg) \
204 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 2); \
206 #define WARNINGL2(condition,msg) \
209 ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 0); \
212 #else //NEKTAR_FULLDEBUG
213 #define ASSERTL2(condition,msg)
214 #define WARNINGL2(condition,msg)
215 #endif //NEKTAR_FULLDEBUG
217 #endif //ERRORUTIL_HPP
NekError(const std::string &message)
static bool HasCustomErrorStream()
static void SetErrorStream(std::ostream &o)
static boost::optional< std::ostream & > outStream
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level)