Nektar++
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 62 of file ErrorUtil.hpp.

63  {
64  efatal,
65  ewarning
66  };

Function Documentation

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

Definition at line 74 of file ErrorUtil.hpp.

References efatal, and ewarning.

Referenced by Error().

75  {
76  // The user of outStream is primarily for the unit tests.
77  // The unit tests often generate errors on purpose to make sure
78  // invalid usage is flagged appropriately. Printing the error
79  // messages to cerr made the unit test output hard to parse.
80 
81  std::string baseMsg = std::string("Level ") +
82  boost::lexical_cast<std::string>(level) +
83  std::string(" assertion violation\n") +
84 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
85  std::string("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("[") + boost::lexical_cast<std::string>(lineNumber) + std::string("]\n") + std::string("Message : ") +
86 #endif
87  msg;
88 
89  std::string btMessage("");
90 #if defined(NEKTAR_FULLDEBUG)
91 #ifndef _WIN32
92  void *btArray[40];
93  int btSize;
94  char **btStrings;
95 
96  btSize = backtrace(btArray, 40);
97  btStrings = backtrace_symbols(btArray, btSize);
98 
99  for (int i = 0 ; i < btSize ; ++i)
100  {
101  btMessage += std::string(btStrings[i]) + "\n";
102  }
103  free(btStrings);
104 #endif
105 #endif
106  switch(type)
107  {
108  case efatal:
109  if( outStream )
110  {
111  (*outStream) << btMessage;
112  (*outStream) << "Fatal : " << baseMsg << std::endl;
113  }
114  else
115  {
116  std::cerr << btMessage;
117  std::cerr << std::endl << "Fatal : " << baseMsg << std::endl;
118  }
119 
120  throw NekError(baseMsg);
121  break;
122 
123  case ewarning:
124  if( outStream )
125  {
126  (*outStream) << btMessage;
127  (*outStream) << "Warning: " << baseMsg << std::endl;
128  }
129  else
130  {
131  std::cerr << btMessage;
132  std::cerr << "Warning: " << baseMsg << std::endl;
133  }
134  break;
135 
136  default:
137  std::cerr << "Unknown warning type: " << baseMsg << std::endl;
138  }
139  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:50
static void ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const std::string &  msg,
unsigned int  level 
)
inlinestatic

Definition at line 141 of file ErrorUtil.hpp.

References Error().

142  {
143  Error(type, routine, lineNumber, msg.c_str(), level);
144  }
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
Definition: ErrorUtil.hpp:146
static void ErrorUtil::Error ( ErrType  type,
const char *  routine,
int  lineNumber,
const char *  msg 
)
inlinestatic

Definition at line 146 of file ErrorUtil.hpp.

References Error().

147  {
148  Error(type, routine, lineNumber, msg, 0);
149  }
static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
Definition: ErrorUtil.hpp:146
static bool ErrorUtil::HasCustomErrorStream ( )
inlinestatic

Definition at line 57 of file ErrorUtil.hpp.

58  {
59  return outStream ? true : false;
60  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:50
static void ErrorUtil::SetErrorStream ( std::ostream &  o)
inlinestatic

Definition at line 52 of file ErrorUtil.hpp.

53  {
54  outStream = o;
55  }
static boost::optional< std::ostream & > outStream
Definition: ErrorUtil.hpp:50

Variable Documentation

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

Definition at line 50 of file ErrorUtil.hpp.