10 #ifndef TEUCHOS_TEST_FOR_EXCEPTION_H
11 #define TEUCHOS_TEST_FOR_EXCEPTION_H
54 #ifdef HAVE_TEUCHOS_STACKTRACE
55 # define TEUCHOS_STORE_STACKTRACE() \
56 if (Teuchos::TestForException_getEnableStacktrace()) { \
57 Teuchos::store_stacktrace(); \
60 # define TEUCHOS_STORE_STACKTRACE()
146 #define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) \
148 const bool throw_exception = (throw_exception_test); \
149 if(throw_exception) { \
150 Teuchos::TestForException_incrThrowNumber(); \
151 const int throwNumber = Teuchos::TestForException_getThrowNumber(); \
152 std::ostringstream omsg; \
154 << __FILE__ << ":" << __LINE__ << ":\n\n" \
155 << "Throw number = " << throwNumber \
157 << "Throw test that evaluated to true: "#throw_exception_test \
160 const std::string &omsgstr = omsg.str(); \
161 TEUCHOS_STORE_STACKTRACE(); \
162 Teuchos::TestForException_break(omsgstr, throwNumber); \
163 throw Exception(omsgstr); \
209 #define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg) \
211 TEUCHOS_TEST_FOR_EXCEPTION( (throw_exception_test), Exception, \
212 Teuchos::typeName(*this) << "::" << tfecfFuncName << msg ) \
223 #define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) \
225 const bool throw_exception = (throw_exception_test); \
226 if(throw_exception) { \
227 Teuchos::TestForException_incrThrowNumber(); \
228 const int throwNumber = Teuchos::TestForException_getThrowNumber(); \
229 std::ostringstream omsg; \
231 omsg << "\n\nThrow number = " << throwNumber << "\n\n"; \
232 const std::string &omsgstr = omsg.str(); \
233 Teuchos::TestForException_break(omsgstr, throwNumber); \
234 TEUCHOS_STORE_STACKTRACE(); \
235 throw Exception(omsgstr); \
257 #define TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) \
259 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg); \
261 catch(const std::exception &except) { \
262 std::ostream *l_out_ptr = (out_ptr); \
265 << "\nThrowing an std::exception of type \'"<<Teuchos::typeName(except) \
266 <<"\' with the error message: " \
285 #define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test) \
286 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, "Error!")
305 #define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) \
306 TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, msg)
322 #define TEUCHOS_TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) \
323 TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, std::logic_error, "Error!", out_ptr)
334 #define TEUCHOS_TRACE(exc)\
336 std::ostringstream omsg; \
337 omsg << exc.what() << std::endl \
338 << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
339 throw std::runtime_error(omsg.str()); \
357 #define TEUCHOS_TEST_FOR_TERMINATION(terminate_test, msg) \
359 const bool call_terminate = (terminate_test); \
360 if (call_terminate) { \
361 std::ostringstream omsg; \
363 << __FILE__ << ":" << __LINE__ << ":\n\n" \
364 << "Terminate test that evaluated to true: "#terminate_test \
367 auto str = omsg.str(); \
368 Teuchos::TestForTermination_terminate(str); \
372 #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.
#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, 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.