oomph::OomphLibException Class Reference

#include <oomph_definitions.h>

+ Inheritance diagram for oomph::OomphLibException:

Public Member Functions

void disable_error_message ()
 

Protected Member Functions

 OomphLibException (const std::string &error_description, const std::string &function_name, const char *location, const std::string &exception_type, std::ostream &exception_stream, const unsigned &output_width, bool list_trace_back)
 
 ~OomphLibException () throw ()
 The destructor cannot throw an exception (C++ STL standard) More...
 

Protected Attributes

std::ostream * Exception_stream_pt
 Exception stream to which we write message in destructor. More...
 
std::stringstream * Exception_stringstream_pt
 String stream that records the error message. More...
 
bool Suppress_error_message
 

Detailed Description

//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// ===================================================================== A Base class for oomph-lib run-time exception (error and warning) handling.

The class can only be instantiated by the derived classes OomphLibError and OomphLibWarning. The (protected) constructor combines its string arguments into a standard format for uniform exception reports which are written to the specified output stream.

Constructor & Destructor Documentation

◆ OomphLibException()

oomph::OomphLibException::OomphLibException ( const std::string &  error_description,
const std::string &  function_name,
const char location,
const std::string &  exception_type,
std::ostream &  exception_stream,
const unsigned output_width,
bool  list_trace_back 
)
protected

Constructor takes the error description, function name and a location string provided by the OOMPH_EXCEPTION_LOCATION macro and combines them into a standard header. The exception type will be the string "WARNING" or "ERROR" and the message is written to the exception_stream, with a specified output_width. Optionally provide a traceback of the function calls.

The OomphLibException constructor takes the error description, function name, a location string provided by the OOMPH_EXCEPTION_LOCATION and an exception type "WARNING" or "ERROR" and combines them into a standard error message that is written to the exception stream. The output_width of the message can also be specified. Optionally provide a traceback of the function calls.

151  : std::runtime_error("OomphException")
152  {
153  // By default we shout
154  Suppress_error_message = false;
155 
156  // Store exception stream
157  Exception_stream_pt = &exception_stream;
158 
159  // Create storage for error message
160  Exception_stringstream_pt = new std::stringstream;
161 
162  // Build an exception header string from the information passed
163  // Start with a couple of new lines to space things out
164  std::string exception_header = "\n\n";
165 
166  // Now add a dividing line
167  for (unsigned i = 0; i < output_width; i++)
168  {
169  exception_header += "=";
170  }
171  exception_header += "\n";
172 
173  // Write the type of exception
174  exception_header += "Oomph-lib ";
175  exception_header += exception_type;
176 
177  // Add the function in which it occurs
178  exception_header += "\n\n at ";
179  exception_header += location;
180  exception_header += "\n\n in ";
181  exception_header += function_name;
182 
183  // Finish with two new lines
184  exception_header += "\n\n";
185 
186  // and a closing line
187  for (unsigned i = 0; i < (unsigned)(0.8 * output_width); i++)
188  {
189  exception_header += "-";
190  }
191 
192  // Output the error header to the stream
193  (*Exception_stringstream_pt) << exception_header << std::endl;
194 
195  // Report the error
196  (*Exception_stringstream_pt) << std::endl << error_description << std::endl;
197 
198 #ifdef OOMPH_HAS_STACKTRACE
199  // Print the stacktrace
200  if (list_trace_back)
201  {
203  }
204 #endif
205 
206  // Finish off with another set of double lines
207  for (unsigned i = 0; i < output_width; i++)
208  {
209  (*Exception_stringstream_pt) << "=";
210  }
211  (*Exception_stringstream_pt) << std::endl << std::endl;
212 
213  // Copy message to stream in terminate helper in case the message
214  // doesn't get caught and/or doesn/t make it to the destructor
215  (*TerminateHelper::Exception_stringstream_pt)
216  << (*Exception_stringstream_pt).str();
217  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
std::stringstream * Exception_stringstream_pt
String stream that records the error message.
Definition: oomph_definitions.h:209
std::ostream * Exception_stream_pt
Exception stream to which we write message in destructor.
Definition: oomph_definitions.h:206
bool Suppress_error_message
Definition: oomph_definitions.h:213
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
static void print_stacktrace(std::ostream &exception_stream, unsigned int max_frames=63)
Definition: stacktrace.h:47

References Exception_stream_pt, Exception_stringstream_pt, i, print_stacktrace(), oomph::Global_string_for_annotation::string(), and Suppress_error_message.

◆ ~OomphLibException()

oomph::OomphLibException::~OomphLibException ( )
throw (
)
protected

The destructor cannot throw an exception (C++ STL standard)

//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// The OomphLibException destructor actually spawns the error message created in the constructor (unless suppresed)

127  {
129  {
130  (*Exception_stream_pt) << (*Exception_stringstream_pt).str();
131  }
134  }

References Exception_stringstream_pt, and Suppress_error_message.

Member Function Documentation

◆ disable_error_message()

void oomph::OomphLibException::disable_error_message ( )
inline

Suppress issueing of the error message in destructor (useful if error is caught successfully!)

179  {
180  // Suppress output of message in destructor...
181  Suppress_error_message = true;
182 
183  // ...and in the big cleanup operation at the end
185  }
void suppress_exception_error_messages()
Suppress error messages (e.g. because error has been caught)
Definition: oomph_definitions.cc:72

References Suppress_error_message, and oomph::TerminateHelper::suppress_exception_error_messages().

Member Data Documentation

◆ Exception_stream_pt

std::ostream* oomph::OomphLibException::Exception_stream_pt
protected

Exception stream to which we write message in destructor.

Referenced by OomphLibException().

◆ Exception_stringstream_pt

std::stringstream* oomph::OomphLibException::Exception_stringstream_pt
protected

String stream that records the error message.

Referenced by OomphLibException(), and ~OomphLibException().

◆ Suppress_error_message

bool oomph::OomphLibException::Suppress_error_message
protected

Boolean to suppress issuing of the error message in destructor (useful if error is caught successfully!)

Referenced by disable_error_message(), OomphLibException(), and ~OomphLibException().


The documentation for this class was generated from the following files: