gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool

GAMBIT exception base class. More...

#include <exceptions.hpp>

Inheritance diagram for Gambit::exception:
Collaboration diagram for Gambit::exception:

Public Member Functions

virtual ~exception () throw ()
 Destructor. More...
 
void set_fatal (bool)
 Setter for the fatal flag. More...
 
virtual const char * what () const throw ()
 Retrieve the identity of the exception. More...
 
void raise (const std::string &, const std::string &)
 Raise the exception. More...
 
 exception (const char *, const char *, const char *, const char *, bool)
 ConstructorsConstructor without log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag)
 Constructor with 1 log tag. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag, LogTag)
 Constructor with 2 log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag, LogTag, LogTag)
 Constructor with 3 log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag, LogTag, LogTag, LogTag)
 Constructor with 4 log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag, LogTag, LogTag, LogTag, LogTag)
 Constructor with 5 log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag)
 Constructor with 6 log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag)
 Constructor with 7 log tags. More...
 
 exception (const char *, const char *, const char *, const char *, bool, std::set< LogTag >)
 Constructor with log tags as a set. More...
 
void forced_throw (const std::string &, const std::string &)
 Force a throw of the exception. More...
 
void silent_forced_throw ()
 As per forced_throw but without logging. More...
 

Static Public Member Functions

static const std::map< const char *, exception * > & all_exceptions ()
 Get a read-only map of pointers to all instances of this class. More...
 
static void set_parameters (std::string)
 Set the parameter point string to append if a fatal exception is thrown. More...
 

Protected Attributes

std::set< LogTagmyLogTags
 The set of tags to be passed to the logger. More...
 

Private Member Functions

void log_exception (const std::string &, const std::string &)
 Log the details of the exception. More...
 
void throw_iff_outside_parallel ()
 Throw the exception onward if running serially, abort if not. More...
 
void abort_here_and_now ()
 Cause the code to print the exception and abort. More...
 

Static Private Member Functions

static std::map< const char *, exception * > & exception_map ()
 Get a map of pointers to all instances of this class. More...
 

Private Attributes

const char * myKind
 The kind of exception (error, warning, etc; for logging). More...
 
std::string myWhat
 What sort of exception this is (for returning with what method). More...
 
const std::string myShortWhat
 Initial value of myWhat. More...
 
const char * myMessage
 The message to be logged when this exception is raised. More...
 
bool isFatal
 Flag indicating if this exception should be considered fatal or not. More...
 

Static Private Attributes

static std::string parameters = ""
 Shared string indicating the current values of the paramters. More...
 

Detailed Description

GAMBIT exception base class.

Definition at line 40 of file exceptions.hpp.

Constructor & Destructor Documentation

◆ exception() [1/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool   
)

ConstructorsConstructor without log tags.

◆ exception() [2/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag   
)

Constructor with 1 log tag.

◆ exception() [3/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag  ,
LogTag   
)

Constructor with 2 log tags.

◆ exception() [4/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag  ,
LogTag  ,
LogTag   
)

Constructor with 3 log tags.

◆ exception() [5/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag   
)

Constructor with 4 log tags.

◆ exception() [6/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag   
)

Constructor with 5 log tags.

◆ exception() [7/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag   
)

Constructor with 6 log tags.

◆ exception() [8/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag  ,
LogTag   
)

Constructor with 7 log tags.

◆ exception() [9/9]

Gambit::exception::exception ( const char *  ,
const char *  ,
const char *  ,
const char *  ,
bool  ,
std::set< LogTag  
)

Constructor with log tags as a set.

◆ ~exception()

virtual Gambit::exception::~exception ( )
throw (
)
inlinevirtual

Destructor.

Definition at line 67 of file exceptions.hpp.

67 {}

Member Function Documentation

◆ abort_here_and_now()

void Gambit::exception::abort_here_and_now ( )
private

Cause the code to print the exception and abort.

Definition at line 276 of file exceptions.cpp.

277  {
278  #pragma omp critical (GAMBIT_exception)
279  {
280  cerr << endl << " \033[00;31;1mFATAL ERROR\033[00m" << endl << endl
281  << "GAMBIT has exited with fatal exception: " << what() << endl
282  << "Please note: this error occurred inside an OpenMP parallel " << endl
283  << "region and so caused a hard stop. If you are running in MPI " << endl
284  << "mode, other processes were not informed of this error and " << endl
285  << "may have to be killed manually (though your MPI implementation " << endl
286  << "may automatically kill them). For more 'gentle' handling of " << endl
287  << "errors in OpenMP loops, please raise errors using the Piped_exceptions system." << endl;
288  #ifdef WITH_MPI
289  GMPI::Comm().Abort();
290  #else
291  abort();
292  #endif
293  }
294  }
virtual const char * what() const
Retrieve the identity of the exception.
Definition: exceptions.cpp:184

◆ all_exceptions()

const std::map< const char *, exception * > & Gambit::exception::all_exceptions ( )
static

Get a read-only map of pointers to all instances of this class.

Definition at line 219 of file exceptions.cpp.

220  {
221  return exception_map();
222  }
static std::map< const char *, exception * > & exception_map()
Get a map of pointers to all instances of this class.
Definition: exceptions.cpp:233

◆ exception_map()

std::map< const char *, exception * > & Gambit::exception::exception_map ( )
staticprivate

Get a map of pointers to all instances of this class.

Definition at line 233 of file exceptions.cpp.

234  {
235  static std::map<const char*,exception*> local_map;
236  return local_map;
237  }

◆ forced_throw()

void Gambit::exception::forced_throw ( const std::string &  origin,
const std::string &  specific_message 
)

Force a throw of the exception.

Log the exception and throw it regardless of whether is is fatal or not.

These should only be used inside a try block, i.e. if you plan to catch the exception.

Log the exception and throw it regardless of whether is is fatal or not.

Definition at line 203 of file exceptions.cpp.

204  {
205  #pragma omp critical (GAMBIT_exception)
206  {
207  log_exception(origin, specific_message+parameters);
208  }
209  throw(*this);
210  }
void log_exception(const std::string &, const std::string &)
Log the details of the exception.
Definition: exceptions.cpp:240

◆ log_exception()

void Gambit::exception::log_exception ( const std::string &  origin,
const std::string &  specific_message 
)
private

Log the details of the exception.

Definition at line 240 of file exceptions.cpp.

References Gambit::EOM, Gambit::LogTags::fatal, Gambit::logger(), and Gambit::LogTags::nonfatal.

241  {
242  std::ostringstream msg;
243  msg << myKind << ": " << myMessage << std::endl
244  << specific_message << std::endl
245  << "Raised at: " << origin << ".";
246  if (isFatal)
247  {
248  logger() << fatal;
249  std::ostringstream myLongWhat;
250  myLongWhat << myShortWhat << std::endl << msg.str();
251  myWhat = myLongWhat.str();
252  }
253  else
254  {
255  logger() << nonfatal;
257  }
258  for (std::set<LogTag>::iterator it = myLogTags.begin(); it != myLogTags.end(); ++it) { logger() << *it; }
259  logger() << msg.str() << EOM;
260  }
std::set< LogTag > myLogTags
The set of tags to be passed to the logger.
Definition: exceptions.hpp:98
const Logging::endofmessage EOM
Explicit const instance of the end of message struct in Gambit namespace.
Definition: logger.hpp:100
EXPORT_SYMBOLS Logging::LogMaster & logger()
Function to retrieve a reference to the Gambit global log object.
Definition: logger.cpp:95
const char * myKind
The kind of exception (error, warning, etc; for logging).
Definition: exceptions.hpp:115
const std::string myShortWhat
Initial value of myWhat.
Definition: exceptions.hpp:121
std::string myWhat
What sort of exception this is (for returning with what method).
Definition: exceptions.hpp:118
const char * myMessage
The message to be logged when this exception is raised.
Definition: exceptions.hpp:124
Here is the call graph for this function:

◆ raise()

void Gambit::exception::raise ( const std::string &  origin,
const std::string &  specific_message 
)

Raise the exception.

Log the exception and, if it is considered fatal, actually throw it. This is the canonical way to trigger a GAMBIT error or warning.

Log the exception and, if it is considered fatal, actually throw it. This is the regular way to trigger a GAMBIT error or warning.

Definition at line 192 of file exceptions.cpp.

193  {
194  str full_message = isFatal ? specific_message+parameters : specific_message;
195  #pragma omp critical (GAMBIT_exception)
196  {
197  log_exception(origin, full_message);
198  }
199  if (isFatal) throw_iff_outside_parallel();
200  }
void throw_iff_outside_parallel()
Throw the exception onward if running serially, abort if not.
Definition: exceptions.cpp:263
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
static std::string parameters
Shared string indicating the current values of the paramters.
Definition: exceptions.hpp:130
void log_exception(const std::string &, const std::string &)
Log the details of the exception.
Definition: exceptions.cpp:240
bool isFatal
Flag indicating if this exception should be considered fatal or not.
Definition: exceptions.hpp:127

◆ set_fatal()

void Gambit::exception::set_fatal ( bool  fatal)

Setter for the fatal flag.

Definition at line 175 of file exceptions.cpp.

References Gambit::LogTags::fatal.

176  {
177  #pragma omp critical (GAMBIT_exception)
178  {
179  isFatal = fatal;
180  }
181  }
bool isFatal
Flag indicating if this exception should be considered fatal or not.
Definition: exceptions.hpp:127

◆ set_parameters()

void Gambit::exception::set_parameters ( std::string  params)
static

Set the parameter point string to append if a fatal exception is thrown.

Definition at line 225 of file exceptions.cpp.

226  {
227  parameters = params;
228  }
static std::string parameters
Shared string indicating the current values of the paramters.
Definition: exceptions.hpp:130

◆ silent_forced_throw()

void Gambit::exception::silent_forced_throw ( )

As per forced_throw but without logging.

Definition at line 213 of file exceptions.cpp.

214  {
215  throw(*this);
216  }

◆ throw_iff_outside_parallel()

void Gambit::exception::throw_iff_outside_parallel ( )
private

Throw the exception onward if running serially, abort if not.

Definition at line 263 of file exceptions.cpp.

264  {
265  if (omp_get_level()==0) // If not in an OpenMP parallel block, throw onwards
266  {
267  throw(*this);
268  }
269  else
270  {
271  abort_here_and_now(); // If in an OpenMP parallel block, just abort immediately.
272  }
273  }
void abort_here_and_now()
Cause the code to print the exception and abort.
Definition: exceptions.cpp:276

◆ what()

const char * Gambit::exception::what ( ) const
throw (
)
virtual

Retrieve the identity of the exception.

Definition at line 184 of file exceptions.cpp.

185  {
186  return myWhat.c_str();
187  }
std::string myWhat
What sort of exception this is (for returning with what method).
Definition: exceptions.hpp:118

Member Data Documentation

◆ isFatal

bool Gambit::exception::isFatal
private

Flag indicating if this exception should be considered fatal or not.

Definition at line 127 of file exceptions.hpp.

◆ myKind

const char* Gambit::exception::myKind
private

The kind of exception (error, warning, etc; for logging).

Definition at line 115 of file exceptions.hpp.

◆ myLogTags

std::set<LogTag> Gambit::exception::myLogTags
protected

The set of tags to be passed to the logger.

Definition at line 98 of file exceptions.hpp.

◆ myMessage

const char* Gambit::exception::myMessage
private

The message to be logged when this exception is raised.

Definition at line 124 of file exceptions.hpp.

◆ myShortWhat

const std::string Gambit::exception::myShortWhat
private

Initial value of myWhat.

Definition at line 121 of file exceptions.hpp.

◆ myWhat

std::string Gambit::exception::myWhat
private

What sort of exception this is (for returning with what method).

Definition at line 118 of file exceptions.hpp.

◆ parameters

str Gambit::exception::parameters = ""
staticprivate

Shared string indicating the current values of the paramters.

Definition at line 130 of file exceptions.hpp.


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