Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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)
 
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 
)
inlinestatic

Definition at line 78 of file ErrorUtil.hpp.

References efatal, and ewarning.

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;
98  MPI_Initialized(&flag);
99  if(flag)
100  {
101  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
102  }
103 #endif
104 
105  std::string btMessage("");
106 #if defined(NEKTAR_FULLDEBUG)
107 #ifndef _WIN32
108  void *btArray[40];
109  int btSize;
110  char **btStrings;
111 
112  btSize = backtrace(btArray, 40);
113  btStrings = backtrace_symbols(btArray, btSize);
114 
115  for (int i = 0 ; i < btSize ; ++i)
116  {
117  btMessage += std::string(btStrings[i]) + "\n";
118  }
119  free(btStrings);
120 #endif
121 #endif
122 
123  switch (type)
124  {
125  case efatal:
126  if (!rank)
127  {
128  if (outStream)
129  {
130  (*outStream) << btMessage;
131  (*outStream) << "Fatal : " << baseMsg << std::endl;
132  }
133  else
134  {
135  std::cerr << btMessage;
136  std::cerr << std::endl << "Fatal : " << baseMsg
137  << std::endl;
138  }
139  }
140 #if defined(NEKTAR_USE_MPI)
141  if (flag)
142  {
143  MPI_Barrier(MPI_COMM_WORLD);
144  }
145 #endif
146  throw NekError(baseMsg);
147  break;
148  case ewarning:
149  if (!rank)
150  {
151  if (outStream)
152  {
153  (*outStream) << btMessage;
154  (*outStream) << "Warning: " << baseMsg << std::endl;
155  }
156  else
157  {
158  std::cerr << btMessage;
159  std::cerr << "Warning: " << baseMsg << std::endl;
160  }
161  }
162  break;
163  default:
164  std::cerr << "Unknown warning type: " << baseMsg << std::endl;
165  }
166  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:54
static void ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const std::string &  msg,
unsigned int  level 
)
inlinestatic

Definition at line 168 of file ErrorUtil.hpp.

References Error().

169  {
170  Error(type, routine, lineNumber, msg.c_str(), level);
171  }
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
Definition: ErrorUtil.hpp:173
static void ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const char *  msg 
)
inlinestatic

Definition at line 173 of file ErrorUtil.hpp.

References Error().

174  {
175  Error(type, routine, lineNumber, msg, 0);
176  }
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
Definition: ErrorUtil.hpp:173
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.