38 #ifndef GMM_EXCEPT_H__
39 #define GMM_EXCEPT_H__
55 class gmm_error:
public std::logic_error {
57 gmm_error(
const std::string& what_arg,
int errorLevel = 1):
58 std::logic_error (what_arg), errorLevel_(errorLevel) {}
59 int errLevel()
const {
return errorLevel_; }
65 #ifdef GMM_HAVE_PRETTY_FUNCTION
66 # define GMM_PRETTY_FUNCTION __PRETTY_FUNCTION__
68 # define GMM_PRETTY_FUNCTION __FUNCTION__
70 # define GMM_PRETTY_FUNCTION ""
83 #if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
84 inline void short_error_throw(
const char *file,
int line,
const char *func,
85 const char *errormsg) {
86 std::stringstream msg__;
87 msg__ <<
"Error in " << file <<
", line " << line <<
" " << func
88 <<
": \n" << errormsg << std::ends;
89 throw gmm::gmm_error(msg__.str());
91 # define GMM_THROW_(type, errormsg) { \
92 std::stringstream msg__; \
93 msg__ << "Error in " << __FILE__ << ", line " \
94 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \
95 << errormsg << std::ends; \
96 throw (type)(msg__.str()); \
99 # define GMM_THROW_AT_LEVEL(errormsg, level) \
101 std::stringstream msg; \
102 msg << "Error in " << __FILE__ << ", line " \
103 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \
104 << errormsg << std::ends; \
105 throw gmm::gmm_error(msg.str(), level); \
110 # define abort_no_return() ::abort()
113 # define abort_no_return() { assert("GMM ABORT"==0); throw "GMM ABORT"; }
116 inline void short_error_throw(
const char *file,
int line,
const char *func,
117 const char *errormsg) {
118 std::stringstream msg__;
119 msg__ <<
"Error in " << file <<
", line " << line <<
" " << func
120 <<
": \n" << errormsg << std::ends;
121 std::cerr << msg__.str() << std::endl;
125 # define GMM_THROW_(type, errormsg) { \
126 std::stringstream msg__; \
127 msg__ << "Error in " << __FILE__ << ", line " \
128 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \
130 std::cerr << msg__.str() << std::endl; \
134 # define GMM_THROW_AT_LEVEL(errormsg, level) \
136 std::stringstream msg__; \
137 msg__ << "Error in " << __FILE__ << ", line " \
138 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \
139 << errormsg << " at level " << level; \
140 std::cerr << msg__.str() << std::endl; \
146 inline void GMM_THROW() {}
147 #define GMM_THROW(a, b) { GMM_THROW_(a,b); gmm::GMM_THROW(); }
149 # define GMM_THROW_DEFAULT(errormsg) GMM_THROW_AT_LEVEL(errormsg, 1)
152 #ifndef GMM_ASSERT_LEVEL
154 # define GMM_ASSERT_LEVEL 1
155 #elif defined(DEBUG_MODE)
156 # define GMM_ASSERT_LEVEL 3
158 # define GMM_ASSERT_LEVEL 2
163 # define GMM_ASSERT1(test, errormsg) { if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 1); }
165 #if GMM_ASSERT_LEVEL < 2
166 # define GMM_ASSERT2(test, errormsg) {}
167 # define GMM_ASSERT3(test, errormsg) {}
168 #elif GMM_ASSERT_LEVEL < 3
169 # define GMM_ASSERT2(test, errormsg){ if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 2); }
170 # define GMM_ASSERT3(test, errormsg){}
172 # define GMM_ASSERT2(test, errormsg){ if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 2); }
173 # define GMM_ASSERT3(test, errormsg){ if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 3); }
181 #ifndef GMM_WARNING_LEVEL
182 # define GMM_WARNING_LEVEL 4
191 #define GMM_WARNING_MSG(level_, thestr) { \
192 std::stringstream msg__; \
193 msg__ << "Level " << level_ << " Warning in " << __FILE__ << ", line " \
194 << __LINE__ << ": " << thestr; \
195 gmm::feedback_manager::manage()->send(msg__.str(), gmm::FeedbackType::WARNING, level_); \
198 #define GMM_WARNING0(thestr) GMM_WARNING_MSG(0, thestr)
201 #if GMM_WARNING_LEVEL > 0
202 # define GMM_WARNING1(thestr) \
203 { if (1 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(1, thestr) }
205 # define GMM_WARNING1(thestr) {}
208 #if GMM_WARNING_LEVEL > 1
209 # define GMM_WARNING2(thestr) \
210 { if (2 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(2, thestr) }
212 # define GMM_WARNING2(thestr) {}
215 #if GMM_WARNING_LEVEL > 2
216 # define GMM_WARNING3(thestr) \
217 { if (3 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(3, thestr) }
219 # define GMM_WARNING3(thestr) {}
222 #if GMM_WARNING_LEVEL > 3
223 # define GMM_WARNING4(thestr) \
224 { if (4 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(4, thestr) }
226 # define GMM_WARNING4(thestr) {}
234 #ifndef GMM_TRACES_LEVEL
235 # define GMM_TRACES_LEVEL 4
244 #define GMM_TRACE_MSG_MPI
245 #define GMM_TRACE_MSG(level_, thestr) { \
246 GMM_TRACE_MSG_MPI { \
247 std::stringstream msg__; \
248 msg__ << "Trace " << level_ << " in " << __FILE__ << ", line " \
249 << __LINE__ << ": " << thestr; \
250 gmm::feedback_manager::send(msg__.str(), gmm::FeedbackType::TRACE, level_); \
254 #define GMM_TRACE_SIMPLE_MSG(level_, thestr) { \
255 GMM_TRACE_MSG_MPI { \
256 std::stringstream msg__; \
257 msg__ << "Trace " << level_ << ": " << thestr; \
258 gmm::feedback_manager::send(msg__.str(), gmm::FeedbackType::TRACE, level_); \
262 #define GMM_TRACE0(thestr) GMM_TRACE_MSG(0, thestr)
263 #define GMM_SIMPLE_TRACE0(thestr) GMM_TRACE_MSG_SIMPLE(0, thestr)
265 #if GMM_TRACES_LEVEL > 0
266 # define GMM_TRACE1(thestr) \
267 { if (1 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(1, thestr) }
268 # define GMM_SIMPLE_TRACE1(thestr) \
269 { if (1 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(1, thestr) }
271 # define GMM_TRACE1(thestr) {}
272 # define GMM_SIMPLE_TRACE1(thestr) {}
275 #if GMM_TRACES_LEVEL > 1
276 # define GMM_TRACE2(thestr) \
277 { if (2 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(2, thestr) }
278 # define GMM_SIMPLE_TRACE2(thestr) \
279 { if (2 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(2, thestr) }
281 # define GMM_TRACE2(thestr) {}
282 # define GMM_SIMPLE_TRACE2(thestr) {}
285 #if GMM_TRACES_LEVEL > 2
286 # define GMM_TRACE3(thestr) \
287 { if (3 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(3, thestr) }
288 # define GMM_SIMPLE_TRACE3(thestr) \
289 { if (3 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(3, thestr) }
291 # define GMM_TRACE3(thestr) {}
292 # define GMM_SIMPLE_TRACE3(thestr) {}
295 #if GMM_TRACES_LEVEL > 3
296 # define GMM_TRACE4(thestr) \
297 { if (4 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(4, thestr) }
298 # define GMM_SIMPLE_TRACE4(thestr) \
299 { if (4 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(4, thestr) }
301 # define GMM_TRACE4(thestr) {}
302 # define GMM_SIMPLE_TRACE4(thestr) {}
305 #define GMM_STANDARD_CATCH_ERROR \
306 catch(const gmm::gmm_error &e) \
308 std::stringstream strStream; \
309 strStream << "============================================\n"; \
310 strStream << "| A GMM error has been detected !!! |\n"; \
311 strStream << "============================================\n"; \
312 strStream << e.what() << std::endl << std::endl; \
313 gmm::feedback_manager::send(strStream.str(), \
314 gmm::FeedbackType::ASSERT, e.errLevel()); \
315 gmm::feedback_manager::terminating_action(); \
317 catch(const std::logic_error &e) \
319 std::stringstream strStream; \
320 strStream << "============================================\n"; \
321 strStream << "| An error has been detected !!! |\n"; \
322 strStream << "============================================\n"; \
323 strStream << e.what() << std::endl << std::endl; \
324 gmm::feedback_manager::send(strStream.str(), \
325 gmm::FeedbackType::ASSERT, 0); \
326 gmm::feedback_manager::terminating_action(); \
328 catch(const std::runtime_error &e) \
330 std::stringstream strStream; \
331 strStream << "============================================\n"; \
332 strStream << "| A runtime error has been detected !!! |\n"; \
333 strStream << "============================================\n"; \
334 strStream << e.what() << std::endl << std::endl; \
335 gmm::feedback_manager::send(strStream.str(), \
336 gmm::FeedbackType::ASSERT, 0); \
337 gmm::feedback_manager::terminating_action(); \
339 catch(const std::bad_alloc &) \
341 std::stringstream strStream; \
342 strStream << "============================================\n"; \
343 strStream << "| A bad allocation has been detected !!! |\n"; \
344 strStream << "============================================\n"; \
345 gmm::feedback_manager::send(strStream.str(), \
346 gmm::FeedbackType::ASSERT, 0); \
347 gmm::feedback_manager::terminating_action(); \
349 catch(const std::bad_typeid &) \
351 std::stringstream strStream; \
352 strStream << "============================================\n"; \
353 strStream << "| A bad typeid has been detected !!! |\n"; \
354 strStream << "============================================\n"; \
355 gmm::feedback_manager::send(strStream.str(), \
356 gmm::FeedbackType::ASSERT, 0); \
357 gmm::feedback_manager::terminating_action(); \
359 catch(const std::bad_exception &) \
361 std::stringstream strStream; \
362 strStream << "============================================\n"; \
363 strStream << "| A bad exception has been detected !!! |\n"; \
364 strStream << "============================================\n"; \
365 gmm::feedback_manager::send(strStream.str(), \
366 gmm::FeedbackType::ASSERT, 0); \
367 gmm::feedback_manager::terminating_action(); \
369 catch(const std::bad_cast &) \
371 std::stringstream strStream; \
372 strStream << "============================================\n"; \
373 strStream << "| A bad_cast has been detected !!! |\n"; \
374 strStream << "============================================\n"; \
375 gmm::feedback_manager::send(strStream.str(), \
376 gmm::FeedbackType::ASSERT, 0); \
377 gmm::feedback_manager::terminating_action(); \
381 std::stringstream strStream; \
382 strStream << "============================================\n"; \
383 strStream << "| An unknown error has been detected !!! |\n"; \
384 strStream << "============================================\n"; \
385 gmm::feedback_manager::send(strStream.str(), \
386 gmm::FeedbackType::ASSERT, 0); \
387 gmm::feedback_manager::terminating_action(); \
396 #if defined(__GNUC__) && (__GNUC__ > 3) && !defined(__clang__)
397 # define GMM_SET_EXCEPTION_DEBUG \
398 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
400 # define GMM_SET_EXCEPTION_DEBUG
Support for run time management of trace, warning and assert feedback.
basic setup for gmm (includes, typedefs etc.)