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 56 of file ErrorUtil.hpp.

Member Enumeration Documentation

◆ ErrType

Enumerator
efatal 
ewarning 

Definition at line 67 of file ErrorUtil.hpp.

68  {
69  efatal,
70  ewarning
71  };

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 193 of file ErrorUtil.hpp.

194  {
195  Error(type, routine, lineNumber, msg, 0);
196  }
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level, bool DoComm=false)
Definition: ErrorUtil.hpp:88

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 88 of file ErrorUtil.hpp.

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

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 188 of file ErrorUtil.hpp.

189  {
190  Error(type, routine, lineNumber, msg.c_str(), level);
191  }

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

◆ HasCustomErrorStream()

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

Definition at line 83 of file ErrorUtil.hpp.

84  {
85  return m_outStream != &std::cerr;
86  }
static std::ostream * m_outStream
Definition: ErrorUtil.hpp:199

References m_outStream.

◆ SetErrorStream()

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

Definition at line 73 of file ErrorUtil.hpp.

74  {
75  m_outStream = &o;
76  }

References m_outStream.

Referenced by BOOST_PYTHON_MODULE().

◆ SetPrintBacktrace()

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

Definition at line 78 of file ErrorUtil.hpp.

79  {
80  m_printBacktrace = b;
81  }

References m_printBacktrace.

Member Data Documentation

◆ m_outStream

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

Definition at line 199 of file ErrorUtil.hpp.

Referenced by HasCustomErrorStream(), and SetErrorStream().

◆ m_printBacktrace

bool Nektar::ErrorUtil::m_printBacktrace = true
staticprivate

Definition at line 200 of file ErrorUtil.hpp.

Referenced by Error(), and SetPrintBacktrace().