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 void TestForException_incrThrowNumber();
00045
00047 int TestForException_getThrowNumber();
00048
00050 void TestForException_break( const std::string &msg );
00051
00115 #define TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg) \
00116 { \
00117 const bool throw_exception = (throw_exception_test); \
00118 if(throw_exception) { \
00119 TestForException_incrThrowNumber(); \
00120 std::ostringstream omsg; \
00121 omsg \
00122 << __FILE__ << ":" << __LINE__ << ":\n\n" \
00123 << "Throw number = " << TestForException_getThrowNumber() << "\n\n" \
00124 << "Throw test that evaluated to true: "#throw_exception_test << "\n\n" \
00125 << msg; \
00126 const std::string &omsgstr = omsg.str(); \
00127 TestForException_break(omsgstr); \
00128 throw Exception(omsgstr); \
00129 } \
00130 }
00131
00137 #define TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test,Exception,msg) \
00138 { \
00139 const bool throw_exception = (throw_exception_test); \
00140 if(throw_exception) { \
00141 TestForException_incrThrowNumber(); \
00142 std::ostringstream omsg; \
00143 omsg << msg; \
00144 omsg << "\n\nThrow number = " << TestForException_getThrowNumber() << "\n\n"; \
00145 const std::string &omsgstr = omsg.str(); \
00146 TestForException_break(omsgstr); \
00147 throw Exception(omsgstr); \
00148 } \
00149 }
00150
00161 #define TEST_FOR_EXCEPT(throw_exception_test) \
00162 TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,"Error!")
00163
00176 #define TEST_FOR_EXCEPT_MSG(throw_exception_test,msg) \
00177 TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,msg)
00178
00192 #define TEST_FOR_EXCEPTION_PRINT(throw_exception_test,Exception,msg,out_ptr) \
00193 try { \
00194 TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg); \
00195 } \
00196 catch(const std::exception &except) { \
00197 std::ostream *l_out_ptr = (out_ptr); \
00198 if(l_out_ptr) { \
00199 *l_out_ptr \
00200 << "\nThorwing an std::exception of type \'"<<Teuchos::typeName(except)<<"\' with the error message: " \
00201 << except.what(); \
00202 } \
00203 throw; \
00204 }
00205
00215 #define TEST_FOR_EXCEPT_PRINT(throw_exception_test,out_ptr) \
00216 TEST_FOR_EXCEPTION_PRINT(throw_exception_test,std::logic_error,"Error!",out_ptr)
00217
00218
00224 #define TEUCHOS_TRACE(exc)\
00225 { \
00226 std::ostringstream omsg; \
00227 omsg << exc.what() << std::endl \
00228 << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
00229 throw std::runtime_error(omsg.str()); \
00230 }
00231
00232
00234
00235 #endif // TEUCHOS_TEST_FOR_EXCEPTION_H