Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_TestForException.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
12
13#include <iostream>
14
15//
16// ToDo: Make these functions thread-safe!
17//
18
19
20namespace {
21
22
23int throwNumber = 0;
24
25
26bool& loc_enableStackTrace()
27{
28 static bool static_enableStackTrace =
29#ifdef HAVE_TEUCHOS_DEFAULT_STACKTRACE
30 true
31#else
32 false
33#endif
34 ;
35 return static_enableStackTrace;
36}
37
38
39} // namespace
40
41
46
47
52
53
55{
56 (void)throwNumber; // Ignore unused arg
57 // Provide a statement to break on
58 size_t break_on_me;
59 break_on_me = errorMsg.length(); // Use errMsg to avoid compiler warning.
60 if (break_on_me) {} // Avoid warning
61 // Above is just some statement for the debugger to break on. Note: now is
62 // a good time to examine the stack trace and look at the error message in
63 // 'errorMsg' to see what happened. In GDB just type 'where' or you can go
64 // up by typing 'up' and moving up in the stack trace to see where you are
65 // and how you got to this point in the code where you are throwing this
66 // exception! Typing in a 'p errorMsg' will show you what the error message
67 // is. Also, you should consider adding a conditional break-point in this
68 // function based on a specific value of 'throwNumber' if the exception you
69 // want to examine is not the first exception thrown.
70}
71
72
77
78
83
84void Teuchos::TestForTermination_terminate(const std::string &msg) {
85 std::ostringstream omsg;
86 if (GlobalMPISession::getNProc() > 1) {
87 omsg << "p="<<GlobalMPISession::getRank()<<": ";
88 }
89 omsg << msg << "\n";
90 std::cerr << omsg.str();
91 std::terminate();
92}
93// NOTE: The above usage of ostringstream is so that the output to std::cerr
94// is done as one string. This should help to avoid jumbled output like is
95// occurring in tests that grep for this output (see #3163).
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Standard test and throw macros.
Smart reference counting pointer class for automatic garbage collection.
TEUCHOSCORE_LIB_DLL_EXPORT int TestForException_getThrowNumber()
Increment the throw number.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_setEnableStacktrace(bool enableStrackTrace)
Set at runtime if stacktracing functionality is enabled when * exceptions are thrown.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_break(const std::string &msg, int throwNumber)
The only purpose for this function is to set a breakpoint.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_incrThrowNumber()
Increment the throw number.
TEUCHOSCORE_LIB_DLL_EXPORT bool TestForException_getEnableStacktrace()
Get at runtime if stacktracing functionality is enabled when exceptions are thrown.
TEUCHOSCORE_LIB_DLL_EXPORT void TestForTermination_terminate(const std::string &msg)
Prints the message to std::cerr and calls std::terminate.