42 #ifndef TEUCHOS_TEST_FOR_EXCEPTION_H
43 #define TEUCHOS_TEST_FOR_EXCEPTION_H
85 #ifdef HAVE_TEUCHOS_STACKTRACE
86 # define TEUCHOS_STORE_STACKTRACE() \
87 if (Teuchos::TestForException_getEnableStacktrace()) { \
88 Teuchos::store_stacktrace(); \
91 # define TEUCHOS_STORE_STACKTRACE()
170 #define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) \
172 const bool throw_exception = (throw_exception_test); \
173 if(throw_exception) { \
174 Teuchos::TestForException_incrThrowNumber(); \
175 std::ostringstream omsg; \
177 << __FILE__ << ":" << __LINE__ << ":\n\n" \
178 << "Throw number = " << Teuchos::TestForException_getThrowNumber() \
180 << "Throw test that evaluated to true: "#throw_exception_test \
183 const std::string &omsgstr = omsg.str(); \
184 TEUCHOS_STORE_STACKTRACE(); \
185 Teuchos::TestForException_break(omsgstr); \
186 throw Exception(omsgstr); \
232 #define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg) \
234 TEUCHOS_TEST_FOR_EXCEPTION( (throw_exception_test), Exception, \
235 Teuchos::typeName(*this) << "::" << tfecfFuncName << msg ) \
246 #define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) \
248 const bool throw_exception = (throw_exception_test); \
249 if(throw_exception) { \
250 Teuchos::TestForException_incrThrowNumber(); \
251 std::ostringstream omsg; \
253 omsg << "\n\nThrow number = " << Teuchos::TestForException_getThrowNumber() << "\n\n"; \
254 const std::string &omsgstr = omsg.str(); \
255 Teuchos::TestForException_break(omsgstr); \
256 TEUCHOS_STORE_STACKTRACE(); \
257 throw Exception(omsgstr); \
279 #define TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) \
281 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg); \
283 catch(const std::exception &except) { \
284 std::ostream *l_out_ptr = (out_ptr); \
287 << "\nThrowing an std::exception of type \'"<<Teuchos::typeName(except) \
288 <<"\' with the error message: " \
307 #define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test) \
308 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, "Error!")
327 #define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) \
328 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, msg)
344 #define TEUCHOS_TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) \
345 TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, std::logic_error, "Error!", out_ptr)
356 #define TEUCHOS_TRACE(exc)\
358 std::ostringstream omsg; \
359 omsg << exc.what() << std::endl \
360 << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
361 throw std::runtime_error(omsg.str()); \
379 #define TEUCHOS_TEST_FOR_TERMINATION(terminate_test, msg) \
381 const bool call_terminate = (terminate_test); \
382 if (call_terminate) { \
383 std::ostringstream omsg; \
385 << __FILE__ << ":" << __LINE__ << ":\n\n" \
386 << "Terminate test that evaluated to true: "#terminate_test \
389 auto str = omsg.str(); \
390 Teuchos::TestForTermination_terminate(str); \
394 #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[[noreturn]] void TestForTermination_terminate(const std::string &msg)
Prints the message to std::cerr and calls std::terminate.
#define TEUCHOSCORE_LIB_DLL_EXPORT
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)
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.