Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Enumerations | Functions | Variables
ErrorUtil Namespace Reference

Classes

class  NekError
 

Enumerations

enum  ErrType { efatal, ewarning }
 

Functions

static void SetErrorStream (std::ostream &o)
 
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)
 

Variables

static boost::optional
< std::ostream & > 
outStream
 

Enumeration Type Documentation

Enumerator
efatal 
ewarning 

Definition at line 66 of file ErrorUtil.hpp.

67  {
68  efatal,
69  ewarning
70  };

Function Documentation

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

Definition at line 78 of file ErrorUtil.hpp.

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

Referenced by Error().

79  {
80  // The user of outStream is primarily for the unit tests.
81  // The unit tests often generate errors on purpose to make sure
82  // invalid usage is flagged appropriately. Printing the error
83  // messages to cerr made the unit test output hard to parse.
84 
85  std::string baseMsg = std::string("Level ") +
86  boost::lexical_cast<std::string>(level) +
87  std::string(" assertion violation\n") +
88 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
89  std::string("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("[") + boost::lexical_cast<std::string>(lineNumber) + std::string("]\n") + std::string("Message : ") +
90 #endif
91  msg;
92 
93  // Default rank is zero. If MPI used and initialised, populate with
94  // the correct rank. Messages are only printed on rank zero.
95  int rank = 0;
96 #if defined(NEKTAR_USE_MPI)
97  int flag = 0;
98  if(DoComm)
99  {
100  MPI_Initialized(&flag);
101  if(flag)
102  {
103  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
104  }
105  }
106 #endif
107 
108  std::string btMessage("");
109 #if defined(NEKTAR_FULLDEBUG)
110 #ifndef _WIN32
111  void *btArray[40];
112  int btSize;
113  char **btStrings;
114 
115  btSize = backtrace(btArray, 40);
116  btStrings = backtrace_symbols(btArray, btSize);
117 
118  for (int i = 0 ; i < btSize ; ++i)
119  {
120  btMessage += std::string(btStrings[i]) + "\n";
121  }
122  free(btStrings);
123 #endif
124 #endif
125 
126  switch (type)
127  {
128  case efatal:
129  if (!rank)
130  {
131  if (outStream)
132  {
133  (*outStream) << btMessage;
134  (*outStream) << "Fatal : " << baseMsg << std::endl;
135  }
136  else
137  {
138  std::cerr << btMessage;
139  std::cerr << std::endl << "Fatal : " << baseMsg
140  << std::endl;
141  }
142  }
143 #if defined(NEKTAR_USE_MPI)
144  if(DoComm)
145  {
146  if (flag)
147  {
148  MPI_Barrier(MPI_COMM_WORLD);
149  }
150  }
151 #endif
152  throw NekError(baseMsg);
153  break;
154  case ewarning:
155  if (!rank)
156  {
157  if (outStream)
158  {
159  (*outStream) << btMessage;
160  (*outStream) << "Warning: " << baseMsg << std::endl;
161  }
162  else
163  {
164  std::cerr << btMessage;
165  std::cerr << "Warning: " << baseMsg << std::endl;
166  }
167  }
168  break;
169  default:
170  std::cerr << "Unknown warning type: " << baseMsg << std::endl;
171  }
172  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:54
string msg
print "Adding",units.name, hash(units), units.description(), print "(was",id(_u),"now",id(units),")" Ensure referenced units exist
Definition: pycml.py:3834
static void ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const std::string &  msg,
unsigned int  level 
)
inlinestatic

Definition at line 174 of file ErrorUtil.hpp.

References Error().

175  {
176  Error(type, routine, lineNumber, msg.c_str(), level);
177  }
string msg
print "Adding",units.name, hash(units), units.description(), print "(was",id(_u),"now",id(units),")" Ensure referenced units exist
Definition: pycml.py:3834
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
Definition: ErrorUtil.hpp:179
static void ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const char *  msg 
)
inlinestatic

Definition at line 179 of file ErrorUtil.hpp.

References Error().

180  {
181  Error(type, routine, lineNumber, msg, 0);
182  }
string msg
print "Adding",units.name, hash(units), units.description(), print "(was",id(_u),"now",id(units),")" Ensure referenced units exist
Definition: pycml.py:3834
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
Definition: ErrorUtil.hpp:179
static bool ErrorUtil::HasCustomErrorStream ( )
inlinestatic

Definition at line 61 of file ErrorUtil.hpp.

62  {
63  return outStream ? true : false;
64  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:54
static void ErrorUtil::SetErrorStream ( std::ostream &  o)
inlinestatic

Definition at line 56 of file ErrorUtil.hpp.

57  {
58  outStream = o;
59  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:54

Variable Documentation

boost::optional<std::ostream&> ErrorUtil::outStream
static

Definition at line 54 of file ErrorUtil.hpp.