Teuchos_TestForException.hpp

Go to the documentation of this file.
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 
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 
00116 #define TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg) \
00117 { \
00118     const bool throw_exception = (throw_exception_test); \
00119     if(throw_exception) { \
00120       TestForException_incrThrowNumber(); \
00121       std::ostringstream omsg; \
00122       omsg \
00123         << __FILE__ << ":" << __LINE__ << ":\n\n" \
00124         << "Throw number = " << TestForException_getThrowNumber() << "\n\n" \
00125         << "Throw test that evaluated to true: "#throw_exception_test << "\n\n" \
00126         << msg; \
00127       const std::string &omsgstr = omsg.str(); \
00128       TestForException_break(omsgstr); \
00129       throw Exception(omsgstr); \
00130     } \
00131 }
00132 
00138 #define TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test,Exception,msg) \
00139 { \
00140     const bool throw_exception = (throw_exception_test); \
00141     if(throw_exception) { \
00142       TestForException_incrThrowNumber(); \
00143       std::ostringstream omsg; \
00144       omsg << msg; \
00145       omsg << "\n\nThrow number = " << TestForException_getThrowNumber() << "\n\n"; \
00146       const std::string &omsgstr = omsg.str(); \
00147       TestForException_break(omsgstr); \
00148       throw Exception(omsgstr); \
00149     } \
00150 }
00151 
00163 #define TEST_FOR_EXCEPT(throw_exception_test) \
00164   TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,"Error!")
00165 
00179 #define TEST_FOR_EXCEPTION_PRINT(throw_exception_test,Exception,msg,out_ptr) \
00180 try { \
00181   TEST_FOR_EXCEPTION(throw_exception_test,Exception,msg); \
00182 } \
00183 catch(const std::exception &except) { \
00184   std::ostream *l_out_ptr = (out_ptr); \
00185   if(l_out_ptr) { \
00186     *l_out_ptr \
00187       << "\nThorwing an std::exception of type \'"<<Teuchos::typeName(except)<<"\' with the error message: " \
00188       << except.what(); \
00189   } \
00190   throw; \
00191 }
00192 
00203 #define TEST_FOR_EXCEPT_PRINT(throw_exception_test,out_ptr) \
00204   TEST_FOR_EXCEPTION_PRINT(throw_exception_test,std::logic_error,"Error!",out_ptr)
00205 
00206 
00211 #define TEUCHOS_TRACE(exc)\
00212 { \
00213   std::ostringstream omsg; \
00214   omsg << exc.what() << std::endl \
00215        << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
00216   throw std::runtime_error(omsg.str()); \
00217 }
00218 
00219 
00221 
00222 #endif // TEUCHOS_TEST_FOR_EXCEPTION_H

Generated on Tue Oct 20 12:45:26 2009 for Teuchos - Trilinos Tools Package by doxygen 1.4.7