40 #include <boost/lexical_cast.hpp>
41 #include <boost/optional.hpp>
44 #if defined(NEKTAR_USE_MPI)
63 return outStream ?
true :
false;
75 NekError(
const std::string& message) :
std::runtime_error(message) {}
78 inline static void Error(
ErrType type,
const char *routine,
int lineNumber,
const char *
msg,
unsigned int level,
bool DoComm =
false)
85 std::string baseMsg = std::string(
"Level ") +
86 boost::lexical_cast<std::string>(level) +
87 std::string(
" assertion violation\n") +
88 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
89 std::string(
"Where : ") + boost::lexical_cast<std::string>(routine) + std::string(
"[") + boost::lexical_cast<std::string>(lineNumber) + std::string(
"]\n") + std::string(
"Message : ") +
96 #if defined(NEKTAR_USE_MPI)
100 MPI_Initialized(&flag);
103 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
108 std::string btMessage(
"");
109 #if defined(NEKTAR_FULLDEBUG)
115 btSize = backtrace(btArray, 40);
116 btStrings = backtrace_symbols(btArray, btSize);
118 for (
int i = 0 ; i < btSize ; ++i)
120 btMessage += std::string(btStrings[i]) +
"\n";
133 (*outStream) << btMessage;
134 (*outStream) <<
"Fatal : " << baseMsg << std::endl;
138 std::cerr << btMessage;
139 std::cerr << std::endl <<
"Fatal : " << baseMsg
143 #if defined(NEKTAR_USE_MPI)
148 MPI_Barrier(MPI_COMM_WORLD);
159 (*outStream) << btMessage;
160 (*outStream) <<
"Warning: " << baseMsg << std::endl;
164 std::cerr << btMessage;
165 std::cerr <<
"Warning: " << baseMsg << std::endl;
170 std::cerr <<
"Unknown warning type: " << baseMsg << std::endl;
174 inline static void Error(
ErrType type,
const char *routine,
int lineNumber,
const std::string&
msg,
unsigned int level)
176 Error(type, routine, lineNumber, msg.c_str(), level);
179 inline static void Error(
ErrType type,
const char *routine,
int lineNumber,
const char *
msg)
181 Error(type, routine, lineNumber, msg, 0);
191 #define NEKERROR(type, msg) \
192 ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0);
195 #define ROOTONLY_NEKERROR(type, msg) \
196 ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0,true);
198 #define ASSERTL0(condition,msg) \
201 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 0); \
204 #define WARNINGL0(condition,msg) \
207 ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 0); \
214 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
216 #define ASSERTL1(condition,msg) \
219 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 1); \
221 #define WARNINGL1(condition,msg) \
224 ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 1); \
227 #else //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
228 #define ASSERTL1(condition,msg)
229 #define WARNINGL1(condition,msg)
230 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
236 #ifdef NEKTAR_FULLDEBUG
238 #define ASSERTL2(condition,msg) \
241 ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 2); \
243 #define WARNINGL2(condition,msg) \
246 ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 2); \
249 #else //NEKTAR_FULLDEBUG
250 #define ASSERTL2(condition,msg)
251 #define WARNINGL2(condition,msg)
252 #endif //NEKTAR_FULLDEBUG
254 #endif //ERRORUTIL_HPP
NekError(const std::string &message)
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level, bool DoComm=false)
static bool HasCustomErrorStream()
static void SetErrorStream(std::ostream &o)
static boost::optional< std::ostream & > outStream
string msg
print "Adding",units.name, hash(units), units.description(), print "(was",id(_u),"now",id(units),")" Ensure referenced units exist