39 #ifndef GMM_EXCEPT_H__ 40 #define GMM_EXCEPT_H__ 56 class gmm_error:
public std::logic_error {
58 gmm_error(
const std::string& what_arg,
int errorLevel = 1):
59 std::logic_error (what_arg), errorLevel_(errorLevel) {}
60 int errLevel() {
return errorLevel_;}
66 #ifdef GETFEM_HAVE_PRETTY_FUNCTION 67 # define GMM_PRETTY_FUNCTION __PRETTY_FUNCTION__ 69 # define GMM_PRETTY_FUNCTION __FUNCTION__ 71 # define GMM_PRETTY_FUNCTION "" 84 #if defined(__EXCEPTIONS) || defined(_CPPUNWIND) 85 inline void short_error_throw(
const char *file,
int line,
const char *func,
86 const char *errormsg) {
87 std::stringstream msg__;
88 msg__ <<
"Error in " << file <<
", line " << line <<
" " << func
89 <<
": \n" << errormsg << std::ends;
90 throw gmm::gmm_error(msg__.str());
92 # define GMM_THROW_(type, errormsg) { \ 93 std::stringstream msg__; \ 94 msg__ << "Error in " << __FILE__ << ", line " \ 95 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \ 96 << errormsg << std::ends; \ 97 throw (type)(msg__.str()); \ 100 # define GMM_THROW_AT_LEVEL(errormsg, level) \ 102 std::stringstream msg; \ 103 msg << "Error in " << __FILE__ << ", line " \ 104 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \ 105 << errormsg << std::ends; \ 106 throw gmm::gmm_error(msg.str(), level); \ 111 # define abort_no_return() ::abort() 114 # define abort_no_return() { assert("GMM ABORT"==0); throw "GMM ABORT"; } 117 inline void short_error_throw(
const char *file,
int line,
const char *func,
118 const char *errormsg) {
119 std::stringstream msg__;
120 msg__ <<
"Error in " << file <<
", line " << line <<
" " << func
121 <<
": \n" << errormsg << std::ends;
122 std::cerr << msg__.str() << std::endl;
126 # define GMM_THROW_(type, errormsg) { \ 127 std::stringstream msg__; \ 128 msg__ << "Error in " << __FILE__ << ", line " \ 129 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \ 131 std::cerr << msg__.str() << std::endl; \ 135 # define GMM_THROW_AT_LEVEL(errormsg, level) \ 137 std::stringstream msg__; \ 138 msg__ << "Error in " << __FILE__ << ", line " \ 139 << __LINE__ << " " << GMM_PRETTY_FUNCTION << ": \n" \ 140 << errormsg << " at level " << level; \ 141 std::cerr << msg__.str() << std::endl; \ 147 inline void GMM_THROW() {}
148 #define GMM_THROW(a, b) { GMM_THROW_(a,b); gmm::GMM_THROW(); } 150 # define GMM_THROW_DEFAULT(errormsg) GMM_THROW_AT_LEVEL(errormsg, 1) 153 #ifndef GMM_ASSERT_LEVEL 155 # define GMM_ASSERT_LEVEL 1 156 #elif defined(DEBUG_MODE) 157 # define GMM_ASSERT_LEVEL 3 159 # define GMM_ASSERT_LEVEL 2 164 # define GMM_ASSERT1(test, errormsg) { if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 1); } 166 #if GMM_ASSERT_LEVEL < 2 167 # define GMM_ASSERT2(test, errormsg) {} 168 # define GMM_ASSERT3(test, errormsg) {} 169 #elif GMM_ASSERT_LEVEL < 3 170 # define GMM_ASSERT2(test, errormsg){ if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 2); } 171 # define GMM_ASSERT3(test, errormsg){} 173 # define GMM_ASSERT2(test, errormsg){ if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 2); } 174 # define GMM_ASSERT3(test, errormsg){ if (!(test)) GMM_THROW_AT_LEVEL(errormsg, 3); } 182 #ifndef GMM_WARNING_LEVEL 183 # define GMM_WARNING_LEVEL 4 192 #define GMM_WARNING_MSG(level_, thestr) { \ 193 std::stringstream msg__; \ 194 msg__ << "Level " << level_ << " Warning in " << __FILE__ << ", line " \ 195 << __LINE__ << ": " << thestr; \ 196 gmm::feedback_manager::manage()->send(msg__.str(), gmm::FeedbackType::WARNING, level_); \ 199 #define GMM_WARNING0(thestr) GMM_WARNING_MSG(0, thestr) 202 #if GMM_WARNING_LEVEL > 0 203 # define GMM_WARNING1(thestr) \ 204 { if (1 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(1, thestr) } 206 # define GMM_WARNING1(thestr) {} 209 #if GMM_WARNING_LEVEL > 1 210 # define GMM_WARNING2(thestr) \ 211 { if (2 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(2, thestr) } 213 # define GMM_WARNING2(thestr) {} 216 #if GMM_WARNING_LEVEL > 2 217 # define GMM_WARNING3(thestr) \ 218 { if (3 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(3, thestr) } 220 # define GMM_WARNING3(thestr) {} 223 #if GMM_WARNING_LEVEL > 3 224 # define GMM_WARNING4(thestr) \ 225 { if (4 <= gmm::feedback_manager::warning_level()) GMM_WARNING_MSG(4, thestr) } 227 # define GMM_WARNING4(thestr) {} 235 #ifndef GMM_TRACES_LEVEL 236 # define GMM_TRACES_LEVEL 4 245 #define GMM_TRACE_MSG_MPI // for Parallelized version 246 #define GMM_TRACE_MSG(level_, thestr) { \ 247 GMM_TRACE_MSG_MPI { \ 248 std::stringstream msg__; \ 249 msg__ << "Trace " << level_ << " in " << __FILE__ << ", line " \ 250 << __LINE__ << ": " << thestr; \ 251 gmm::feedback_manager::send(msg__.str(), gmm::FeedbackType::TRACE, level_); \ 255 #define GMM_TRACE_SIMPLE_MSG(level_, thestr) { \ 256 GMM_TRACE_MSG_MPI { \ 257 std::stringstream msg__; \ 258 msg__ << "Trace " << level_ << ": " << thestr; \ 259 gmm::feedback_manager::send(msg__.str(), gmm::FeedbackType::TRACE, level_); \ 263 #define GMM_TRACE0(thestr) GMM_TRACE_MSG(0, thestr) 264 #define GMM_SIMPLE_TRACE0(thestr) GMM_TRACE_MSG_SIMPLE(0, thestr) 266 #if GMM_TRACES_LEVEL > 0 267 # define GMM_TRACE1(thestr) \ 268 { if (1 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(1, thestr) } 269 # define GMM_SIMPLE_TRACE1(thestr) \ 270 { if (1 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(1, thestr) } 272 # define GMM_TRACE1(thestr) {} 273 # define GMM_SIMPLE_TRACE1(thestr) {} 276 #if GMM_TRACES_LEVEL > 1 277 # define GMM_TRACE2(thestr) \ 278 { if (2 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(2, thestr) } 279 # define GMM_SIMPLE_TRACE2(thestr) \ 280 { if (2 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(2, thestr) } 282 # define GMM_TRACE2(thestr) {} 283 # define GMM_SIMPLE_TRACE2(thestr) {} 286 #if GMM_TRACES_LEVEL > 2 287 # define GMM_TRACE3(thestr) \ 288 { if (3 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(3, thestr) } 289 # define GMM_SIMPLE_TRACE3(thestr) \ 290 { if (3 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(3, thestr) } 292 # define GMM_TRACE3(thestr) {} 293 # define GMM_SIMPLE_TRACE3(thestr) {} 296 #if GMM_TRACES_LEVEL > 3 297 # define GMM_TRACE4(thestr) \ 298 { if (4 <= gmm::feedback_manager::traces_level()) GMM_TRACE_MSG(4, thestr) } 299 # define GMM_SIMPLE_TRACE4(thestr) \ 300 { if (4 <= gmm::feedback_manager::traces_level()) GMM_TRACE_SIMPLE_MSG(4, thestr) } 302 # define GMM_TRACE4(thestr) {} 303 # define GMM_SIMPLE_TRACE4(thestr) {} 306 #define GMM_STANDARD_CATCH_ERROR \ 307 catch(gmm::gmm_error e) \ 309 std::stringstream strStream; \ 310 strStream << "============================================\n"; \ 311 strStream << "| A GMM error has been detected !!! |\n"; \ 312 strStream << "============================================\n"; \ 313 strStream << e.what() << std::endl << std::endl; \ 314 gmm::feedback_manager::send(strStream.str(), \ 315 gmm::FeedbackType::ASSERT, e.errLevel()); \ 316 gmm::feedback_manager::terminating_action(); \ 318 catch(std::logic_error e) \ 320 std::stringstream strStream; \ 321 strStream << "============================================\n"; \ 322 strStream << "| An error has been detected !!! |\n"; \ 323 strStream << "============================================\n"; \ 324 strStream << e.what() << std::endl << std::endl; \ 325 gmm::feedback_manager::send(strStream.str(), \ 326 gmm::FeedbackType::ASSERT, 0); \ 327 gmm::feedback_manager::terminating_action(); \ 329 catch(std::runtime_error e) \ 331 std::stringstream strStream; \ 332 strStream << "============================================\n"; \ 333 strStream << "| A runtime error has been detected !!! |\n"; \ 334 strStream << "============================================\n"; \ 335 strStream << e.what() << std::endl << std::endl; \ 336 gmm::feedback_manager::send(strStream.str(), \ 337 gmm::FeedbackType::ASSERT, 0); \ 338 gmm::feedback_manager::terminating_action(); \ 340 catch(std::bad_alloc) \ 342 std::stringstream strStream; \ 343 strStream << "============================================\n"; \ 344 strStream << "| A bad allocation has been detected !!! |\n"; \ 345 strStream << "============================================\n"; \ 346 gmm::feedback_manager::send(strStream.str(), \ 347 gmm::FeedbackType::ASSERT, 0); \ 348 gmm::feedback_manager::terminating_action(); \ 350 catch(std::bad_typeid) \ 352 std::stringstream strStream; \ 353 strStream << "============================================\n"; \ 354 strStream << "| A bad typeid has been detected !!! |\n"; \ 355 strStream << "============================================\n"; \ 356 gmm::feedback_manager::send(strStream.str(), \ 357 gmm::FeedbackType::ASSERT, 0); \ 358 gmm::feedback_manager::terminating_action(); \ 360 catch(std::bad_exception) \ 362 std::stringstream strStream; \ 363 strStream << "============================================\n"; \ 364 strStream << "| A bad exception has been detected !!! |\n"; \ 365 strStream << "============================================\n"; \ 366 gmm::feedback_manager::send(strStream.str(), \ 367 gmm::FeedbackType::ASSERT, 0); \ 368 gmm::feedback_manager::terminating_action(); \ 370 catch(std::bad_cast) \ 372 std::stringstream strStream; \ 373 strStream << "============================================\n"; \ 374 strStream << "| A bad_cast has been detected !!! |\n"; \ 375 strStream << "============================================\n"; \ 376 gmm::feedback_manager::send(strStream.str(), \ 377 gmm::FeedbackType::ASSERT, 0); \ 378 gmm::feedback_manager::terminating_action(); \ 382 std::stringstream strStream; \ 383 strStream << "============================================\n"; \ 384 strStream << "| An unknown error has been detected !!! |\n"; \ 385 strStream << "============================================\n"; \ 386 gmm::feedback_manager::send(strStream.str(), \ 387 gmm::FeedbackType::ASSERT, 0); \ 388 gmm::feedback_manager::terminating_action(); \ 397 #if defined(__GNUC__) && (__GNUC__ > 3) 398 # define GMM_SET_EXCEPTION_DEBUG \ 399 std::set_terminate(__gnu_cxx::__verbose_terminate_handler); 401 # define GMM_SET_EXCEPTION_DEBUG basic setup for gmm (includes, typedefs etc.)
Support for run time management of trace, warning and assert feedback.