42 #ifndef TEUCHOS_TEST_FOR_EXCEPTION_H
43 #define TEUCHOS_TEST_FOR_EXCEPTION_H
86 #ifdef HAVE_TEUCHOS_STACKTRACE
87 # define TEUCHOS_STORE_STACKTRACE() \
88 if (Teuchos::TestForException_getEnableStacktrace()) { \
89 Teuchos::store_stacktrace(); \
92 # define TEUCHOS_STORE_STACKTRACE()
178 #define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) \
180 const bool throw_exception = (throw_exception_test); \
181 if(throw_exception) { \
182 Teuchos::TestForException_incrThrowNumber(); \
183 const int throwNumber = Teuchos::TestForException_getThrowNumber(); \
184 std::ostringstream omsg; \
186 << __FILE__ << ":" << __LINE__ << ":\n\n" \
187 << "Throw number = " << throwNumber \
189 << "Throw test that evaluated to true: "#throw_exception_test \
192 const std::string &omsgstr = omsg.str(); \
193 TEUCHOS_STORE_STACKTRACE(); \
194 Teuchos::TestForException_break(omsgstr, throwNumber); \
195 throw Exception(omsgstr); \
241 #define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg) \
243 TEUCHOS_TEST_FOR_EXCEPTION( (throw_exception_test), Exception, \
244 Teuchos::typeName(*this) << "::" << tfecfFuncName << msg ) \
255 #define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) \
257 const bool throw_exception = (throw_exception_test); \
258 if(throw_exception) { \
259 Teuchos::TestForException_incrThrowNumber(); \
260 const int throwNumber = Teuchos::TestForException_getThrowNumber(); \
261 std::ostringstream omsg; \
263 omsg << "\n\nThrow number = " << throwNumber << "\n\n"; \
264 const std::string &omsgstr = omsg.str(); \
265 Teuchos::TestForException_break(omsgstr, throwNumber); \
266 TEUCHOS_STORE_STACKTRACE(); \
267 throw Exception(omsgstr); \
289 #define TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) \
291 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg); \
293 catch(const std::exception &except) { \
294 std::ostream *l_out_ptr = (out_ptr); \
297 << "\nThrowing an std::exception of type \'"<<Teuchos::typeName(except) \
298 <<"\' with the error message: " \
317 #define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test) \
318 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, "Error!")
337 #define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) \
338 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, msg)
354 #define TEUCHOS_TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) \
355 TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, std::logic_error, "Error!", out_ptr)
366 #define TEUCHOS_TRACE(exc)\
368 std::ostringstream omsg; \
369 omsg << exc.what() << std::endl \
370 << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
371 throw std::runtime_error(omsg.str()); \
389 #define TEUCHOS_TEST_FOR_TERMINATION(terminate_test, msg) \
391 const bool call_terminate = (terminate_test); \
392 if (call_terminate) { \
393 std::ostringstream omsg; \
395 << __FILE__ << ":" << __LINE__ << ":\n\n" \
396 << "Terminate test that evaluated to true: "#terminate_test \
399 auto str = omsg.str(); \
400 Teuchos::TestForTermination_terminate(str); \
404 #endif // TEUCHOS_TEST_FOR_EXCEPTION_H
Functions for returning stacktrace info (GCC only initially).
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_setEnableStacktrace(bool enableStrackTrace)
Set at runtime if stacktracing functionality is enabled when * exceptions are thrown.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForTermination_terminate(const std::string &msg)
Prints the message to std::cerr and calls std::terminate.
TEUCHOSCORE_LIB_DLL_EXPORT int TestForException_getThrowNumber()
Increment the throw number.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_incrThrowNumber()
Increment the throw number.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_break(const std::string &msg, int throwNumber)
The only purpose for this function is to set a breakpoint.
Defines basic traits returning the name of a type in a portable and readable way. ...
TEUCHOSCORE_LIB_DLL_EXPORT bool TestForException_getEnableStacktrace()
Get at runtime if stacktracing functionality is enabled when exceptions are thrown.