Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
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
10
#include "
Teuchos_TestForException.hpp
"
11
#include "
Teuchos_GlobalMPISession.hpp
"
12
13
#include <iostream>
14
15
//
16
// ToDo: Make these functions thread-safe!
17
//
18
19
20
namespace
{
21
22
23
int
throwNumber = 0;
24
25
26
bool
& 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
42
void
Teuchos::TestForException_incrThrowNumber
()
43
{
44
++throwNumber;
45
}
46
47
48
int
Teuchos::TestForException_getThrowNumber
()
49
{
50
return
throwNumber;
51
}
52
53
54
void
Teuchos::TestForException_break
(
const
std::string &errorMsg,
int
throwNumber)
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
73
void
Teuchos::TestForException_setEnableStacktrace
(
bool
enableStrackTrace)
74
{
75
loc_enableStackTrace() = enableStrackTrace;
76
}
77
78
79
bool
Teuchos::TestForException_getEnableStacktrace
()
80
{
81
return
loc_enableStackTrace();
82
}
83
84
void
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).
Teuchos_GlobalMPISession.hpp
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Teuchos_TestForException.hpp
Standard test and throw macros.
Teuchos::GlobalMPISession::getRank
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
Definition
Teuchos_GlobalMPISession.cpp:201
Teuchos::GlobalMPISession::getNProc
static int getNProc()
The number of processes in MPI_COMM_WORLD.
Definition
Teuchos_GlobalMPISession.cpp:208
Teuchos::TestForException_getThrowNumber
TEUCHOSCORE_LIB_DLL_EXPORT int TestForException_getThrowNumber()
Increment the throw number.
Definition
Teuchos_TestForException.cpp:48
Teuchos::TestForException_setEnableStacktrace
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_setEnableStacktrace(bool enableStrackTrace)
Set at runtime if stacktracing functionality is enabled when * exceptions are thrown.
Definition
Teuchos_TestForException.cpp:73
Teuchos::TestForException_break
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_break(const std::string &msg, int throwNumber)
The only purpose for this function is to set a breakpoint.
Definition
Teuchos_TestForException.cpp:54
Teuchos::TestForException_incrThrowNumber
TEUCHOSCORE_LIB_DLL_EXPORT void TestForException_incrThrowNumber()
Increment the throw number.
Definition
Teuchos_TestForException.cpp:42
Teuchos::TestForException_getEnableStacktrace
TEUCHOSCORE_LIB_DLL_EXPORT bool TestForException_getEnableStacktrace()
Get at runtime if stacktracing functionality is enabled when exceptions are thrown.
Definition
Teuchos_TestForException.cpp:79
Teuchos::TestForTermination_terminate
TEUCHOSCORE_LIB_DLL_EXPORT void TestForTermination_terminate(const std::string &msg)
Prints the message to std::cerr and calls std::terminate.
Definition
Teuchos_TestForException.cpp:84
Generated by
1.17.0