Defines | |
| #define | TEUCHOS_ASSERT(assertion_test) TEST_FOR_EXCEPT(!(assertion_test)) |
| This macro is throws when an assert fails. | |
| #define | TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive) |
This macro asserts that an integral number fallis in the range [lower_inclusive,upper_exclusive). | |
| #define | TEUCHOS_ASSERT_EQUALITY(val1, val2) |
| This macro is checks that to numbers are equal and if not then throws an exception with a good error message. | |
| #define | TEUCHOS_ASSERT_INEQUALITY(val1, comp, val2) |
| This macro is checks that an inequality between two numbers is satisified and if not then throws a good exception message. | |
| #define | TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg) |
| Macro for throwing an exception with breakpointing to ease debugging. | |
| #define | TEST_FOR_EXCEPTION_PURE_MSG(throw_exception_test, Exception, msg) |
| Macro for throwing an exception with breakpointing to ease debugging. | |
| #define | TEST_FOR_EXCEPT(throw_exception_test) TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,"Error!") |
This macro is designed to be a short version of TEST_FOR_EXCEPTION() that is easier to call. | |
| #define | TEST_FOR_EXCEPT_MSG(throw_exception_test, msg) TEST_FOR_EXCEPTION(throw_exception_test,std::logic_error,msg) |
This macro is designed to be a short version of TEST_FOR_EXCEPTION() that is easier to call. | |
| #define | TEST_FOR_EXCEPTION_PRINT(throw_exception_test, Exception, msg, out_ptr) |
This macro is the same as TEST_FOR_EXCEPTION() except that the exception will be caught, the message printed, and then rethrown. | |
| #define | TEST_FOR_EXCEPT_PRINT(throw_exception_test, out_ptr) TEST_FOR_EXCEPTION_PRINT(throw_exception_test,std::logic_error,"Error!",out_ptr) |
This macro is the same as TEST_FOR_EXCEPT() except that the exception will be caught, the message printed, and then rethrown. | |
| #define | TEUCHOS_TRACE(exc) |
| This macro intercepts an exception, prints a standardized message including the current filename and line number, and then throws the exception up the stack. | |
Functions | |
| void | TestForException_incrThrowNumber () |
| Increment the throw number. | |
| int | TestForException_getThrowNumber () |
| Increment the throw number. | |
| void | TestForException_break (const std::string &msg) |
| The only purpose for this function is to set a breakpoint. | |
|
|
This macro is throws when an assert fails.
|
|
|
Value: { \
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)<<")!" ); \
}
[lower_inclusive,upper_exclusive).
|
|
|
Value: { \
TEST_FOR_EXCEPTION( \
(val1) != (val2), std::out_of_range, \
"Error, (" #val1 " = " << (val1) << ") != (" #val2 " = " << (val2) << ")!" ); \
}
|
|
|
Value: { \
TEST_FOR_EXCEPTION( \
!( (val1) comp (val2) ), std::out_of_range, \
"Error, (" #val1 " = " << (val1) << ") " \
#comp " (" #val2 " = " << (val2) << ")! FAILED!" ); \
}
|
|
|
Value: { \
const bool throw_exception = (throw_exception_test); \
if(throw_exception) { \
TestForException_incrThrowNumber(); \
std::ostringstream omsg; \
omsg \
<< __FILE__ << ":" << __LINE__ << ":\n\n" \
<< "Throw number = " << TestForException_getThrowNumber() << "\n\n" \
<< "Throw test that evaluated to true: "#throw_exception_test << "\n\n" \
<< msg; \
const std::string &omsgstr = omsg.str(); \
TestForException_break(omsgstr); \
throw Exception(omsgstr); \
} \
}
my_source_file.cpp that the exception std::out_of_range is thrown if n > 100. To use the macro, the source code would contain (at line 225 for instance):
TEST_FOR_EXCEPTION( n > 100, std::out_of_range
, "Error, n = " << n << is bad" );
n = 125 > 100 for instance, the std::out_of_range exception would be thrown with the error message: /home/bob/project/src/my_source_file.cpp:225: n > 100: Error, n = 125 is bad
In order to debug this, simply open your debugger (gdb for instance), set a break point at TEST_FOR_EXCEPTION( obj1->val() > obj2->val(), std::logic_error, "Oh no!" ); double obj1_val = obj1->val(), obj2_val = obj2->val(); TEST_FOR_EXCEPTION( obj1_val > obj2_val, std::logic_error, "Oh no!" );
As an alternative, you can set a breakpoint for any exception thrown by setting a breakpoint in the function |
|
|
Value: { \
const bool throw_exception = (throw_exception_test); \
if(throw_exception) { \
TestForException_incrThrowNumber(); \
std::ostringstream omsg; \
omsg << msg; \
omsg << "\n\nThrow number = " << TestForException_getThrowNumber() << "\n\n"; \
const std::string &omsgstr = omsg.str(); \
TestForException_break(omsgstr); \
throw Exception(omsgstr); \
} \
}
This macro is equivalent to the |
|
|
This macro is designed to be a short version of
|
|
|
This macro is designed to be a short version of
|
|
|
Value: try { \ 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 \ << "\nThorwing an std::exception of type \'"<<Teuchos::typeName(except)<<"\' with the error message: " \ << except.what(); \ } \ throw; \ } TEST_FOR_EXCEPTION() except that the exception will be caught, the message printed, and then rethrown.
|
|
|
This macro is the same as
|
|
|
Value: { \
std::ostringstream omsg; \
omsg << exc.what() << std::endl \
<< "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
throw std::runtime_error(omsg.str()); \
}
|
|
|
Increment the throw number.
|
|
|
Increment the throw number.
|
|
|
The only purpose for this function is to set a breakpoint.
|
1.3.9.1