在过去的几天里,我尝试在我的 Ubuntu 16.04 系统上安装 Dakota v. 6.10。根据将库包含到我的代码中的 dakota.6.10 用户手册,其工作方式如下:
\# include "LibraryEnvironment.hpp" 'front end'
\# include "DirectApplicInterface.hpp" 'back end'
当我尝试编译时,g++ 编译器抛出以下错误:
“/usr/local/dakota/include/Teuchos_as.hpp 在行中。438: 未定义对 `Teuchos::TestForException_incrThrowNumber() 的引用”
多行出现相同的错误:第 438、443、448、553、563、570 行
在 Teuchos_as.hpp 中,Test_For_Exception() 方法被多次使用,但仅在上述行内引用未定义。
在 cmake 安装期间,已找到以下包和库:
C-Compiler GNU 5.4.0
Cxx-Compiler GNU 5.4.0
Fortran-Compiler GNU 5.4.0
Perl 5.22.1
Python 2.7.12
MPI_C, MPI_CXX, MPI_Fortran version 3.0
boost 1.58
cmake --version 3.14.0
cmake_c-, cmake_cxx-compiler 5.4
libblas.so libraryname blas_win32
liblapack.so library name lapack_win32
我尝试在外部安装 trilinos-library,然后将其链接到 dakota cmake 安装。虽然这会在安装过程中引起其他问题。在这种情况下,我使用了 dakota.6.10.src 安装目录附带的 trilinos/teuchos 包。
您能否就如何解决此问题给我任何建议。是否可能需要设置其他全局参数才能使包含正常工作?
*** 控制台错误输出*** 方法“Test_For_Exception()”的所有其他调用的类似输出
Invoking: Cross G++ Linker
g++ -o "SGV" ./src/LossModel/BlockageModelAungier.o ./src/Blade.o ./src/BladeGen.o ./src/BladeSec.o ./src/Blader.o ./src/CGNSexport.o ./src/CSMgenerator.o ./src/ConsoleOut.o ./src/DakotaInterface.o ./src/DataContainer.o ./src/Grid.o ./src/GridGenerator.o ./src/MisesInterface.o ./src/MisesInterfacePost.o ./src/NACAgenerator.o ./src/Nodes.o ./src/PlotData.o ./src/Profile.o ./src/ProfileGenerator.o ./src/ReadFile.o ./src/S1Interface.o ./src/S1SectionPerformance.o ./src/SGV.o ./src/SgvKernel.o ./src/StreamData.o ./src/StreamSec.o ./src/Streamer.o ./src/TraceInterface.o ./src/WriteData.o ./src/spline.o -lsisl -lpython2.7
./src/DakotaInterface.o: In function `double Teuchos::(anonymous namespace)::stringToReal<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double (*)(char const*, char**), char const*)':
/usr/local/dakota/include/Teuchos_as.hpp:553: undefined reference to `Teuchos::TestForException_incrThrowNumber()'
/usr/local/dakota/include/Teuchos_as.hpp:553: undefined reference to `Teuchos::TestForException_getThrowNumber()'
/usr/local/dakota/include/Teuchos_as.hpp:553: undefined reference to `Teuchos::TestForException_break(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/dakota/include/Teuchos_as.hpp:563: undefined reference to `Teuchos::TestForException_incrThrowNumber()'
/usr/local/dakota/include/Teuchos_as.hpp:563: undefined reference to `Teuchos::TestForException_getThrowNumber()'
/usr/local/dakota/include/Teuchos_as.hpp:563: undefined reference to `Teuchos::TestForException_break(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/dakota/include/Teuchos_as.hpp:570: undefined reference to `Teuchos::TestForException_incrThrowNumber()'
/usr/local/dakota/include/Teuchos_as.hpp:570: undefined reference to `Teuchos::TestForException_getThrowNumber()'
/usr/local/dakota/include/Teuchos_as.hpp:570: undefined reference to `Teuchos::TestForException_break(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
./src/DakotaInterface.o: In function `float Teuchos::(anonymous namespace)::stringToReal<float>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float (*)(char const*, char**), char const*)':
makefile:46: recipe for target 'SGV' failed
这些是头文件,我排除了所有不必要的代码部分,错误行适合调用“Test_For_Exception”的行。
*** Teuchos_as.hpp***
#ifndef TEUCHOS_AS_HPP
#define TEUCHOS_AS_HPP
#include "Teuchos_ConfigDefs.hpp"
#include "Teuchos_Assert.hpp"
#include <limits>
#include <cstdlib>
#include <cerrno>
#include <climits>
#ifdef HAVE_TEUCHOS_COMPLEX
#include <complex>
#endif // HAVE_TEUCHOS_COMPLEX
#ifdef HAVE_TEUCHOS_QD
#include <qd/qd_real.h>
#include <qd/dd_real.h>
#endif // HAVE_TEUCHOS_QD
namespace Teuchos {
namespace { // anonymous
/// Helper function for converting the given \c std::string to an
/// integer of type <tt>IntType</tt>.
///
/// \tparam IntType A built-in integer type, like \c int or \c long.
/// It may be signed or unsigned.
///
/// \param t [in] The string to convert.
///
/// \param rawConvert [in] A function with the same arguments as
/// strtol, strtoul, strtoll, or strtoull, which returns
/// <tt>IntType<tt>. It must return the same type as
/// <tt>IntType</tt>. Note that all of these but strtol require
/// C99 support. It's up to you to pick the right function for
/// <tt>IntType</tt>.
///
/// \param intTypeName [in] Human-readable string which is the name
/// of <tt>IntType</tt>.
template<class IntType>
IntType
intToString (const std::string& t,
IntType (*rawConvert) (const char*, char**, int),
const char* intTypeName)
{
// We call the "raw" conversion function instead of using
// std::istringstream, because we want more detailed information
// in case of failure to convert. I have no idea what
// operator>>(std::istream&, unsigned long long&) does if it
// encounters an integer too long to fit in IntType, for example.
//
// mfh 13 Nov 2012: It's fair to assume that if you have "long
// long", then your implementation of the C standard library
// includes strtoul(). Ditto for "unsigned long long" and
// strtoull(). If this is not the case, we could include a
// configure-time test for these functions(), with a fall-back to
// an std::istringstream operator>> implementation.
char* endptr = NULL;
// Keep the pointer, because std::string doesn't necessarily
// guarantee that this is the same across calls to c_str(), does
// it? Or perhaps it does...
const char* t_ptr = t.c_str ();
// We preset errno to 0, to distinguish success or failure after
// calling strtoull. Most implementations of the C standard
// library written with threads in mind have errno be a macro that
// expands to thread-local storage. Thanks to the Linux
// documentation for strtol ("man 3 strtol", Red Hat Enterprise
// Linux 5) for advice with the following checks.
errno = 0;
const IntType val = rawConvert (t_ptr, &endptr, 10);
const IntType minVal = std::numeric_limits<IntType>::min ();
const IntType maxVal = std::numeric_limits<IntType>::max ();
TEUCHOS_TEST_FOR_EXCEPTION(
errno == ERANGE && (val == minVal || val == maxVal),
std::range_error,
"Teuchos::ValueTypeConversionTraits<" << intTypeName << ", std::string>::convert: "
"The integer value in the given string \"" << t << "\" overflows " << intTypeName << ".");
TEUCHOS_TEST_FOR_EXCEPTION(
errno != 0 && val == 0,
std::invalid_argument,
"Teuchos::ValueTypeConversionTraits<" << intTypeName << ", std::string>::convert: "
"The conversion function was unable to convert the given string \"" << t << "\" to " << intTypeName << ".");
TEUCHOS_TEST_FOR_EXCEPTION(
endptr == t_ptr, // See above discussion of c_str().
std::invalid_argument,
"Teuchos::ValueTypeConversionTraits<" << intTypeName << ", std::string>::convert: "
"The conversion function was unable to read any integer digits from the given string "
"\"" << t << "\".");
return val;
}
/// \brief Convert the given string to a RealType floating-point number.
///
/// Helper function for converting the given \c std::string to a
/// real-valued floating-point number of type RealType.
///
/// \tparam RealType The real-valued floating-point type of the
/// return value. We always assume that RealType is default
/// constructible and that <tt>operator>>(std::istream&,
/// RealType&)</tt> is defined. We also assume that <tt>t !=
/// 0</tt> is a well-formed Boolean expression for t of type
/// RealType.
///
/// \param t [in] The string to convert.
///
/// \param rawConvert [in] If not NULL, this must be one of the
/// following C standard library functions: strtod, strtof, or
/// strtold. (strtof and strtold require C99 support.) In that
/// case, we use this function to read the value from the input
/// string. If NULL, we use <tt>operator>>(std::istream&,
/// RealType&)</tt> to read the value from the string (via
/// std::istringstream).
///
/// \param realTypeName [in] Human-readable string which is the name
/// of RealType.
template<class RealType>
RealType
stringToReal (const std::string& t,
RealType (*rawConvert) (const char*, char**),
const char* realTypeName)
{
if (rawConvert == NULL) {
std::istringstream in (t);
RealType out;
in >> out;
return out;
}
else {
char* endptr = NULL;
// Keep the pointer, because std::string doesn't necessarily
// guarantee that this is the same across calls to c_str(), does
// it? Or perhaps it does...
const char* t_ptr = t.c_str ();
// We preset errno to 0, to distinguish success or failure after
// calling strtoull. Most implementations of the C standard
// library written with threads in mind have errno be a macro that
// expands to thread-local storage. Thanks to the Linux
// documentation for strtod ("man 3 strtod", Red Hat Enterprise
// Linux 5) for advice with the following checks.
errno = 0;
const RealType val = rawConvert (t_ptr, &endptr);
TEUCHOS_TEST_FOR_EXCEPTION(
errno == ERANGE && (val != 0),
std::range_error,
"Teuchos::ValueTypeConversionTraits<" << realTypeName
<< ", std::string>::convert: "
"The value in the given string \"" << t << "\" overflows "
<< realTypeName << ".");
//
// mfh 20 Nov 2012: Should we treat underflow as an error?
//
TEUCHOS_TEST_FOR_EXCEPTION(
errno == ERANGE && val == 0,
std::invalid_argument,
"Teuchos::ValueTypeConversionTraits<" << realTypeName
<< ", std::string>::convert: "
"The value in the given string \"" << t << "\" underflows "
<< realTypeName << ".");
TEUCHOS_TEST_FOR_EXCEPTION(
endptr == t_ptr, // See above discussion of c_str().
std::invalid_argument,
"Teuchos::ValueTypeConversionTraits<" << realTypeName
<< ", std::string>::convert: "
"The conversion function was unable to read any floating-point data "
"from the given string \"" << t << "\".");
return val;
}
}
} // namespace (anonymous)
} // end namespace Teuchos
*** Teuchos_Assert.hpp***
#ifndef TEUCHOS_ASSERT_HPP
#define TEUCHOS_ASSERT_HPP
#include "Teuchos_TestForException.hpp"
/** \brief This macro is throws when an assert fails.
*
* \note <tt>The std::exception</tt> thrown is <tt>std::logic_error</tt>.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_ASSERT(assertion_test) TEUCHOS_TEST_FOR_EXCEPT(!(assertion_test))
#ifdef TEUCHOS_DEBUG
/** \brief Behaves as TEUCHOS_ASSERT only if debugging is enabled.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_DEBUG_ASSERT(assertion_test) TEUCHOS_ASSERT(assertion_test)
#else
#define TEUCHOS_DEBUG_ASSERT(assertion_test)
#endif
/** \brief This macro asserts that an integral number fallis in the range
* <tt>[lower_inclusive,upper_exclusive)</tt>
*
* \note <tt>The std::exception</tt> thrown is <tt>std::out_of_range</tt>.
*
* WARNING: This assert will evaluate <tt>index</tt>,
* <tt>lower_inclusive</tt>, and <tt>upper_inclusive</tt> more than once if
* there is a failure which will cause the side-effect of an additional
* evaluation. This is needed because the return types of these values are
* unknown. Therefore, only pass in arguments that are objects or function
* calls that have not side-effects!
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( index, lower_inclusive, upper_exclusive ) \
{ \
TEUCHOS_TEST_FOR_EXCEPTION( \
!( (lower_inclusive) <= (index) && (index) < (upper_exclusive) ), \
std::out_of_range, \
"Error, the index " #index " = " << (index) << " does not fall in the range" \
"["<<(lower_inclusive)<<","<<(upper_exclusive)<<")!" ); \
}
/** \brief This macro is checks that to numbers are equal and if not then
* throws an exception with a good error message.
*
* \note The <tt>std::exception</tt> thrown is <tt>std::out_of_range</tt>.
*
* WARNING: This assert will evaluate <tt>val1</tt> and <tt>val2</tt> more
* than once if there is a failure which will cause the side-effect of an
* additional evaluation. This is needed because the return types of
* <tt>val1</tt> and <tt>val2</tt> are unknown. Therefore, only pass in
* arguments that are objects or function calls that have not side-effects!
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_ASSERT_EQUALITY( val1, val2 ) \
{ \
TEUCHOS_TEST_FOR_EXCEPTION( \
(val1) != (val2), std::out_of_range, \
"Error, (" #val1 " = " << (val1) << ") != (" #val2 " = " << (val2) << ")!" ); \
}
/** \brief This macro is checks that an inequality between two numbers is
* satisified and if not then throws a good exception message.
*
* \note The <tt>std::exception</tt> thrown is <tt>std::out_of_range</tt>.
*
* WARNING: This assert will evaluate <tt>val1</tt> and <tt>val2</tt> more
* than once if there is a failure which will cause the side-effect of an
* additional evaluation. This is needed because the return types of
* <tt>val1</tt> and <tt>val2</tt> are unknown. Therefore, only pass in
* arguments that are objects or function calls that have not side-effects!
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_ASSERT_INEQUALITY( val1, comp, val2 ) \
{ \
TEUCHOS_TEST_FOR_EXCEPTION( \
!( (val1) comp (val2) ), std::out_of_range, \
"Error, (" #val1 " = " << (val1) << ") " \
#comp " (" #val2 " = " << (val2) << ")! FAILED!" ); \
}
#endif // TEUCHOS_ASSERT_HPP
*** Teuchos_TestForException.hpp***
#ifndef TEUCHOS_TEST_FOR_EXCEPTION_H
#define TEUCHOS_TEST_FOR_EXCEPTION_H
/*! \file Teuchos_TestForException.hpp
\brief Standard test and throw macros.
*/
#include "Teuchos_TypeNameTraits.hpp"
#include "Teuchos_stacktrace.hpp"
namespace Teuchos {
/*! \defgroup TestForException_grp Utility code for throwing exceptions and setting breakpoints.
\ingroup teuchos_language_support_grp
*/
/** \brief Increment the throw number. \ingroup TestForException_grp */
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_incrThrowNumber();
/** \brief Increment the throw number. \ingroup TestForException_grp */
TEUCHOSCORE_LIB_DLL_EXPORT int TestForException_getThrowNumber();
/** \brief The only purpose for this function is to set a breakpoint.
\ingroup TestForException_grp */
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_break( const std::string &msg );
/** \brief Set at runtime if stacktracing functionality is enabled when *
exceptions are thrown. \ingroup TestForException_grp */
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_setEnableStacktrace(bool enableStrackTrace);
/** \brief Get at runtime if stacktracing functionality is enabled when
* exceptions are thrown. */
TEUCHOSCORE_LIB_DLL_EXPORT bool TestForException_getEnableStacktrace();
/** \brief Prints the message to std::cerr and calls std::terminate. */
TEUCHOSCORE_LIB_DLL_EXPORT [[noreturn]] void TestForTermination_terminate(const std::string &msg);
} // namespace Teuchos
#ifdef HAVE_TEUCHOS_STACKTRACE
# define TEUCHOS_STORE_STACKTRACE() \
if (Teuchos::TestForException_getEnableStacktrace()) { \
Teuchos::store_stacktrace(); \
}
#else
# define TEUCHOS_STORE_STACKTRACE()
#endif
/** \brief Macro for throwing an exception with breakpointing to ease debugging
*
* \param throw_exception_test [in] Test for when to throw the exception.
* This can and should be an expression that may mean something to the user.
* The text verbatim of this expression is included in the formed error
* string.
*
* \param Exception [in] This should be the name of an exception class. The
* only requirement for this class is that it have a constructor that accepts
* an std::string object (as all of the standard exception classes do).
*
* \param msg [in] This is any expression that can be included in an output
* stream operation. This is useful when buinding error messages on the fly.
* Note that the code in this argument only gets evaluated if
* <tt>throw_exception_test</tt> evaluates to <tt>true</tt> when an exception
* is throw.
*
* The way that this macro is intended to be used is to
* call it in the source code like a function. For example,
* suppose that in a piece of code in the file <tt>my_source_file.cpp</tt>
* that the exception <tt>std::out_of_range</tt> is thrown if <tt>n > 100</tt>.
* To use the macro, the source code would contain (at line 225
* for instance):
\verbatim
TEUCHOS_TEST_FOR_EXCEPTION( n > 100, std::out_of_range,
"Error, n = " << n << is bad" );
\endverbatim
* When the program runs and with <tt>n = 125 > 100</tt> for instance,
* the <tt>std::out_of_range</tt> exception would be thrown with the
* error message:
\verbatim
/home/bob/project/src/my_source_file.cpp:225: n > 100: Error, n = 125 is bad
\endverbatim
*
* In order to debug this, simply open your debugger (gdb for instance),
* set a break point at <tt>my_soure_file.cpp:225</tt> and then set the condition
* to break for <tt>n > 100</tt> (e.g. in gdb the command
* is <tt>cond break_point_number n > 100</tt> and then run the
* program. The program should stop a the point in the source file
* right where the exception will be thrown at but before the exception
* is thrown. Try not to use expression for <tt>throw_exception_test</tt> that
* includes virtual function calls, etc. as most debuggers will not be able to check
* these types of conditions in order to stop at a breakpoint. For example,
* instead of:
\verbatim
TEUCHOS_TEST_FOR_EXCEPTION( obj1->val() > obj2->val(), std::logic_error, "Oh no!" );
\endverbatim
* try:
\verbatim
double obj1_val = obj1->val(), obj2_val = obj2->val();
TEUCHOS_TEST_FOR_EXCEPTION( obj1_val > obj2_val, std::logic_error, "Oh no!" );
\endverbatim
* If the developer goes to the line in the source file that is contained
* in the error message of the exception thrown, he/she will see the
* underlying condition.
*
* As an alternative, you can set a breakpoint for any exception thrown
* by setting a breakpoint in the function <tt>ThrowException_break()</tt>.
*
* NOTE: This macro will only evaluate <tt>throw_exception_test</tt> once
* reguardless if the test fails and the exception is thrown or
* not. Therefore, it is safe to call a function with side-effects as the
* <tt>throw_exception_test</tt> argument.
*
* NOTE: This macro will result in creating a stacktrace snapshot in some
* cases (see the main doc page for details) and will be printed automatically
* when main() uses TEUCHOS_STANDARD_CATCH_STATEMENTS() to catch uncaught
* excpetions.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) \
{ \
const bool throw_exception = (throw_exception_test); \
if(throw_exception) { \
Teuchos::TestForException_incrThrowNumber(); \
std::ostringstream omsg; \
omsg \
<< __FILE__ << ":" << __LINE__ << ":\n\n" \
<< "Throw number = " << Teuchos::TestForException_getThrowNumber() \
<< "\n\n" \
<< "Throw test that evaluated to true: "#throw_exception_test \
<< "\n\n" \
<< msg; \
const std::string &omsgstr = omsg.str(); \
TEUCHOS_STORE_STACKTRACE(); \
Teuchos::TestForException_break(omsgstr); \
throw Exception(omsgstr); \
} \
}
/** \brief Macro for throwing an exception from within a class method with
* breakpointing to ease debugging.
*
* \param throw_exception_test [in] Test for when to throw the exception.
* This can and should be an expression that may mean something to the user.
* The text verbatim of this expression is included in the formed error
* string.
*
* \param Exception [in] This should be the name of an exception class. The
* only requirement for this class is that it have a constructor that accepts
* an std::string object (as all of the standard exception classes do).
*
* \param msg [in] This is any expression that can be included in an output
* stream operation. This is useful when buinding error messages on the fly.
* Note that the code in this argument only gets evaluated if
* <tt>throw_exception_test</tt> evaluates to <tt>true</tt> when an exception
* is throw.
*
* \param tfecfFuncName [implicit] This is a variable in the current scope that is
* required to exist and assumed to contain the name of the current class method.
*
* \param this [implicit] This is the variable (*this), used for printing the
* typename of the enclosing class.
*
* The way that this macro is intended to be used is to call it from a member
* of of a class. It is used similarly to TEUCHOS_TEST_FOR_EXCEPTION, except that it
* assumes that the (above) variables <tt>this</tt> and <tt>fecfFuncName</tt>
* exist and are properly defined. Example usage is:
\code
std::string tfecfFuncName("someMethod");
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( test, std::runtime_error,
": can't call this method in that way.");
\endcode
* See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> for more details.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg) \
{ \
TEUCHOS_TEST_FOR_EXCEPTION( (throw_exception_test), Exception, \
Teuchos::typeName(*this) << "::" << tfecfFuncName << msg ) \
}
/** \brief Macro for throwing an exception with breakpointing to ease debugging
*
* This macro is equivalent to the <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> macro except
* the file name, line number, and test condition are not printed.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) \
{ \
const bool throw_exception = (throw_exception_test); \
if(throw_exception) { \
Teuchos::TestForException_incrThrowNumber(); \
std::ostringstream omsg; \
omsg << msg; \
omsg << "\n\nThrow number = " << Teuchos::TestForException_getThrowNumber() << "\n\n"; \
const std::string &omsgstr = omsg.str(); \
Teuchos::TestForException_break(omsgstr); \
TEUCHOS_STORE_STACKTRACE(); \
throw Exception(omsgstr); \
} \
}
/** \brief This macro is the same as <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> except that the
* exception will be caught, the message printed, and then rethrown.
*
* \param throw_exception_test [in] See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt>.
*
* \param Exception [in] See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt>.
*
* \param msg [in] See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt>.
*
* \param out_ptr [in] If <tt>out_ptr!=NULL</tt> then <tt>*out_ptr</tt> will
* receive a printout of a line of output that gives the exception type and
* the error message that is generated.
*
* See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> for more details.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) \
try { \
TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg); \
} \
catch(const std::exception &except) { \
std::ostream *l_out_ptr = (out_ptr); \
if(l_out_ptr) { \
*l_out_ptr \
<< "\nThrowing an std::exception of type \'"<<Teuchos::typeName(except) \
<<"\' with the error message: " \
<< except.what(); \
} \
throw; \
}
/** \brief This macro is designed to be a short version of
* <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> that is easier to call.
*
* \param throw_exception_test [in] Test for when to throw the exception.
* This can and should be an expression that may mean something to the user.
* The text verbatim of this expression is included in the formed error
* string.
*
* \note The exception thrown is <tt>std::logic_error</tt>.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test) \
TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, "Error!")
/** \brief This macro is designed to be a short version of
* <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> that is easier to call.
*
* \param throw_exception_test [in] Test for when to throw the exception.
* This can and should be an expression that may mean something to the user.
* The text verbatim of this expression is included in the formed error
* string.
*
* \param msg [in] The error message.
*
* \note The exception thrown is <tt>std::logic_error</tt>.
*
* See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> for more details.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) \
TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, std::logic_error, msg)
/** \brief This macro is the same as <tt>TEUCHOS_TEST_FOR_EXCEPT()</tt> except that the
* exception will be caught, the message printed, and then rethrown.
*
* \param throw_exception_test [in] See <tt>TEUCHOS_TEST_FOR_EXCEPT()</tt>.
*
* \param out_ptr [in] If <tt>out_ptr!=NULL</tt> then <tt>*out_ptr</tt> will
* receive a printout of a line of output that gives the exception type and
* the error message that is generated.
*
* See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> for more details.
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) \
TEUCHOS_TEST_FOR_EXCEPTION_PRINT(throw_exception_test, std::logic_error, "Error!", out_ptr)
/** \brief This macro intercepts an exception, prints a standardized message
* including the current filename and line number, and then throws the
* exception up the stack.
*
* \param exc [in] the exception that has been caught
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TRACE(exc)\
{ \
std::ostringstream omsg; \
omsg << exc.what() << std::endl \
<< "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
throw std::runtime_error(omsg.str()); \
}
/** \brief This macro is to be used instead of
* <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt> to report an error in situations
* where an exception can't be throw (like in an destructor).
*
* \param terminate_test [in] See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt>.
*
* \param msg [in] See <tt>TEUCHOS_TEST_FOR_EXCEPTION()</tt>.
*
* If the termination test evaluates to <tt>true</tt>, then
* <tt>std::terminate()</tt> is called (which should bring down an entire
* multi-process MPI program even if only one process calls
* <tt>std::terminate()</tt> with most MPI implementations).
*
* \ingroup TestForException_grp
*/
#define TEUCHOS_TEST_FOR_TERMINATION(terminate_test, msg) \
{ \
const bool call_terminate = (terminate_test); \
if (call_terminate) { \
std::ostringstream omsg; \
omsg \
<< __FILE__ << ":" << __LINE__ << ":\n\n" \
<< "Terminate test that evaluated to true: "#terminate_test \
<< "\n\n" \
<< msg << "\n\n"; \
auto str = omsg.str(); \
Teuchos::TestForTermination_terminate(str); \
} \
}
#endif // TEUCHOS_TEST_FOR_EXCEPTION_H