Nektar++
Classes | Public Types | Static Public Member Functions | Static Private Attributes | List of all members
Nektar::ErrorUtil Class Reference

#include <ErrorUtil.hpp>

Classes

class  NekError
 

Public Types

enum  ErrType { efatal , ewarning }
 

Static Public Member Functions

static void SetErrorStream (std::ostream &o)
 
static void SetPrintBacktrace (bool b)
 
static bool HasCustomErrorStream ()
 
static void Error (ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level, bool DoComm=false)
 
static void Error (ErrType type, const char *routine, int lineNumber, const std::string &msg, unsigned int level)
 
static void Error (ErrType type, const char *routine, int lineNumber, const char *msg)
 

Static Private Attributes

static std::ostream * m_outStream = &std::cerr
 
static bool m_printBacktrace = true
 

Detailed Description

Definition at line 54 of file ErrorUtil.hpp.

Member Enumeration Documentation

◆ ErrType

Enumerator
efatal 
ewarning 

Definition at line 65 of file ErrorUtil.hpp.

Member Function Documentation

◆ Error() [1/3]

static void Nektar::ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const char *  msg 
)
inlinestatic

Definition at line 185 of file ErrorUtil.hpp.

187 {
188 Error(type, routine, lineNumber, msg, 0);
189 }
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level, bool DoComm=false)
Definition: ErrorUtil.hpp:86

References Error(), and CellMLToNektar.pycml::msg.

◆ Error() [2/3]

static void Nektar::ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const char *  msg,
unsigned int  level,
bool  DoComm = false 
)
inlinestatic

Definition at line 86 of file ErrorUtil.hpp.

90 {
91 // The user of outStream is primarily for the unit tests. The unit
92 // tests often generate errors on purpose to make sure invalid usage is
93 // flagged appropriately. Printing the error messages to cerr made the
94 // unit test output hard to parse.
95
96 std::string baseMsg =
97 "Level " + std::to_string(level) + " assertion violation\n";
98#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
99 baseMsg += "Where : " + std::string(routine) + "[" +
100 std::to_string(lineNumber) + "]\nMessage : ";
101#endif
102 baseMsg += std::string(msg);
103
104 // Default rank is zero. If MPI used and initialised, populate with
105 // the correct rank. Messages are only printed on rank zero.
106 int rank = 0;
107#if defined(NEKTAR_USE_MPI) && !defined(NEKTAR_USE_CWIPI)
108 int flag = 0;
109 if (DoComm)
110 {
111 MPI_Initialized(&flag);
112 if (flag)
113 {
114 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
115 }
116 }
117#endif
118
119 std::string btMessage("");
120#if defined(NEKTAR_FULLDEBUG)
121#ifndef _WIN32
123 {
124 void *btArray[40];
125 int btSize;
126 char **btStrings;
127
128 btSize = backtrace(btArray, 40);
129 btStrings = backtrace_symbols(btArray, btSize);
130
131 for (int i = 0; i < btSize; ++i)
132 {
133 btMessage += std::string(btStrings[i]) + "\n";
134 }
135 free(btStrings);
136 }
137#endif
138#endif
139
140 switch (type)
141 {
142 case efatal:
143 if (!rank)
144 {
146 {
147 (*m_outStream) << btMessage;
148 }
149 (*m_outStream) << "Fatal : " << baseMsg << std::endl;
150 }
151
152#if defined(NEKTAR_USE_MPI) && !defined(NEKTAR_USE_CWIPI)
153 if (DoComm)
154 {
155 if (flag)
156 {
157 MPI_Barrier(MPI_COMM_WORLD);
158 }
159 }
160#endif
161 throw NekError(baseMsg);
162 break;
163 case ewarning:
164 if (!rank)
165 {
167 {
168 (*m_outStream) << btMessage;
169 }
170 (*m_outStream) << "Warning : " << baseMsg << std::endl;
171 }
172 break;
173 default:
174 (*m_outStream)
175 << "Unknown warning type: " << baseMsg << std::endl;
176 }
177 }
Nektar::ErrorUtil::NekError NekError
static bool m_printBacktrace
Definition: ErrorUtil.hpp:193

References efatal, ewarning, CellMLToNektar.pycml::level, m_printBacktrace, and CellMLToNektar.pycml::msg.

Referenced by Error().

◆ Error() [3/3]

static void Nektar::ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const std::string &  msg,
unsigned int  level 
)
inlinestatic

Definition at line 179 of file ErrorUtil.hpp.

181 {
182 Error(type, routine, lineNumber, msg.c_str(), level);
183 }

References Error(), CellMLToNektar.pycml::level, and CellMLToNektar.pycml::msg.

◆ HasCustomErrorStream()

static bool Nektar::ErrorUtil::HasCustomErrorStream ( )
inlinestatic

Definition at line 81 of file ErrorUtil.hpp.

82 {
83 return m_outStream != &std::cerr;
84 }
static std::ostream * m_outStream
Definition: ErrorUtil.hpp:192

References m_outStream.

Referenced by Nektar::UnitTests::RedirectCerrIfNeeded().

◆ SetErrorStream()

static void Nektar::ErrorUtil::SetErrorStream ( std::ostream &  o)
inlinestatic

Definition at line 71 of file ErrorUtil.hpp.

72 {
73 m_outStream = &o;
74 }

References m_outStream.

Referenced by BOOST_PYTHON_MODULE(), and Nektar::UnitTests::RedirectCerrIfNeeded().

◆ SetPrintBacktrace()

static void Nektar::ErrorUtil::SetPrintBacktrace ( bool  b)
inlinestatic

Definition at line 76 of file ErrorUtil.hpp.

77 {
79 }

References m_printBacktrace.

Member Data Documentation

◆ m_outStream

std::ostream * Nektar::ErrorUtil::m_outStream = &std::cerr
staticprivate

Definition at line 192 of file ErrorUtil.hpp.

Referenced by HasCustomErrorStream(), and SetErrorStream().

◆ m_printBacktrace

bool Nektar::ErrorUtil::m_printBacktrace = true
staticprivate

Definition at line 193 of file ErrorUtil.hpp.

Referenced by Error(), and SetPrintBacktrace().