|
Teuchos - Trilinos Tools Package Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef TEUCHOS_TEST_FOR_EXCEPTION_H 00030 #define TEUCHOS_TEST_FOR_EXCEPTION_H 00031 00032 #include <Teuchos_TypeNameTraits.hpp> 00033 00038 #include "Teuchos_TypeNameTraits.hpp" 00039 00044 00046 TEUCHOS_LIB_DLL_EXPORT void TestForException_incrThrowNumber(); 00047 00049 TEUCHOS_LIB_DLL_EXPORT int TestForException_getThrowNumber(); 00050 00052 TEUCHOS_LIB_DLL_EXPORT void TestForException_break( const std::string &msg ); 00053 00122 #define TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) \ 00123 { \ 00124 const bool throw_exception = (throw_exception_test); \ 00125 if(throw_exception) { \ 00126 TestForException_incrThrowNumber(); \ 00127 std::ostringstream omsg; \ 00128 omsg \ 00129 << __FILE__ << ":" << __LINE__ << ":\n\n" \ 00130 << "Throw number = " << TestForException_getThrowNumber() << "\n\n" \ 00131 << "Throw test that evaluated to true: "#throw_exception_test << "\n\n" \ 00132 << msg; \ 00133 const std::string &omsgstr = omsg.str(); \ 00134 TestForException_break(omsgstr); \ 00135 throw Exception(omsgstr); \ 00136 } \ 00137 } 00138 00139 00174 #define TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg) \ 00175 { \ 00176 TEST_FOR_EXCEPTION( (throw_exception_test), Exception, \ 00177 typeName(*this) << "::" << tfecfFuncName << msg ) \ 00178 } 00179 00180 00186 #define TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) \ 00187 { \ 00188 const bool throw_exception = (throw_exception_test); \ 00189 if(throw_exception) { \ 00190 TestForException_incrThrowNumber(); \ 00191 std::ostringstream omsg; \ 00192 omsg << msg; \ 00193 omsg << "\n\nThrow number = " << TestForException_getThrowNumber() << "\n\n"; \ 00194 const std::string &omsgstr = omsg.str(); \ 00195 TestForException_break(omsgstr); \ 00196 throw Exception(omsgstr); \ 00197 } \ 00198 } 00199 00210 #define TEST_FOR_EXCEPT(throw_exception_test) \ 00211 TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,"Error!") 00212 00225 #define TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) \ 00226 TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,msg) 00227 00241 #define TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) \ 00242 try { \ 00243 TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg); \ 00244 } \ 00245 catch(const std::exception &except) { \ 00246 std::ostream *l_out_ptr = (out_ptr); \ 00247 if(l_out_ptr) { \ 00248 *l_out_ptr \ 00249 << "\nThorwing an std::exception of type \'"<<Teuchos::typeName(except)<<"\' with the error message: " \ 00250 << except.what(); \ 00251 } \ 00252 throw; \ 00253 } 00254 00264 #define TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) \ 00265 TEST_FOR_EXCEPTION_PRINT(throw_exception_test,std::logic_error,"Error!",out_ptr) 00266 00267 00273 #define TEUCHOS_TRACE(exc)\ 00274 { \ 00275 std::ostringstream omsg; \ 00276 omsg << exc.what() << std::endl \ 00277 << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \ 00278 throw std::runtime_error(omsg.str()); \ 00279 } 00280 00281 00283 00284 #endif // TEUCHOS_TEST_FOR_EXCEPTION_H
1.7.4