00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_TEST_FOR_EXCEPTION_H
00030 #define TEUCHOS_TEST_FOR_EXCEPTION_H
00031
00036 #include "Teuchos_TypeNameTraits.hpp"
00037
00042
00044 TEUCHOS_LIB_DLL_EXPORT void TestForException_incrThrowNumber();
00045
00047 TEUCHOS_LIB_DLL_EXPORT int TestForException_getThrowNumber();
00048
00050 TEUCHOS_LIB_DLL_EXPORT void TestForException_break( const std::string &msg );
00051
00120 #define TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) \
00121 { \
00122 const bool throw_exception = (throw_exception_test); \
00123 if(throw_exception) { \
00124 TestForException_incrThrowNumber(); \
00125 std::ostringstream omsg; \
00126 omsg \
00127 << __FILE__ << ":" << __LINE__ << ":\n\n" \
00128 << "Throw number = " << TestForException_getThrowNumber() << "\n\n" \
00129 << "Throw test that evaluated to true: "#throw_exception_test << "\n\n" \
00130 << msg; \
00131 const std::string &omsgstr = omsg.str(); \
00132 TestForException_break(omsgstr); \
00133 throw Exception(omsgstr); \
00134 } \
00135 }
00136
00142 #define TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) \
00143 { \
00144 const bool throw_exception = (throw_exception_test); \
00145 if(throw_exception) { \
00146 TestForException_incrThrowNumber(); \
00147 std::ostringstream omsg; \
00148 omsg << msg; \
00149 omsg << "\n\nThrow number = " << TestForException_getThrowNumber() << "\n\n"; \
00150 const std::string &omsgstr = omsg.str(); \
00151 TestForException_break(omsgstr); \
00152 throw Exception(omsgstr); \
00153 } \
00154 }
00155
00166 #define TEST_FOR_EXCEPT(throw_exception_test) \
00167 TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,"Error!")
00168
00181 #define TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) \
00182 TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,msg)
00183
00197 #define TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) \
00198 try { \
00199 TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg); \
00200 } \
00201 catch(const std::exception &except) { \
00202 std::ostream *l_out_ptr = (out_ptr); \
00203 if(l_out_ptr) { \
00204 *l_out_ptr \
00205 << "\nThorwing an std::exception of type \'"<<Teuchos::typeName(except)<<"\' with the error message: " \
00206 << except.what(); \
00207 } \
00208 throw; \
00209 }
00210
00220 #define TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) \
00221 TEST_FOR_EXCEPTION_PRINT(throw_exception_test,std::logic_error,"Error!",out_ptr)
00222
00223
00229 #define TEUCHOS_TRACE(exc)\
00230 { \
00231 std::ostringstream omsg; \
00232 omsg << exc.what() << std::endl \
00233 << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
00234 throw std::runtime_error(omsg.str()); \
00235 }
00236
00237
00239
00240 #endif // TEUCHOS_TEST_FOR_EXCEPTION_H