gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
exceptions.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
19 
20 #ifndef __exceptions_hpp__
21 #define __exceptions_hpp__
22 
23 #include <map>
24 #include <set>
25 #include <string>
26 #include <exception>
27 #include <vector>
28 #include <utility>
29 
31 #include "gambit/Logs/log_tags.hpp"
32 
33 namespace Gambit
34 {
35 
36  // Forward declaration of functor class.
37  class functor;
38 
40  class EXPORT_SYMBOLS exception : virtual public std::exception
41  {
42  public:
43 
47  exception(const char*, const char*, const char*, const char*, bool);
49  exception(const char*, const char*, const char*, const char*, bool, LogTag);
51  exception(const char*, const char*, const char*, const char*, bool, LogTag, LogTag);
53  exception(const char*, const char*, const char*, const char*, bool, LogTag, LogTag, LogTag);
55  exception(const char*, const char*, const char*, const char*, bool, LogTag, LogTag, LogTag, LogTag);
57  exception(const char*, const char*, const char*, const char*, bool, LogTag, LogTag, LogTag, LogTag, LogTag);
59  exception(const char*, const char*, const char*, const char*, bool, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag);
61  exception(const char*, const char*, const char*, const char*, bool, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag);
63  exception(const char*, const char*, const char*, const char*, bool, std::set<LogTag>);
65 
67  virtual ~exception() throw() {}
68 
70  void set_fatal(bool);
71 
73  virtual const char* what() const throw();
74 
78  void raise(const std::string&, const std::string&);
79 
84  void forced_throw(const std::string&, const std::string&);
86  void silent_forced_throw();
88 
90  static const std::map<const char*,exception*>& all_exceptions();
91 
93  static void set_parameters(std::string);
94 
95  protected:
96 
98  std::set<LogTag> myLogTags;
99 
100  private:
101 
103  static std::map<const char*,exception*>& exception_map();
104 
106  void log_exception(const std::string&, const std::string&);
107 
109  void throw_iff_outside_parallel();
110 
112  void abort_here_and_now();
113 
115  const char* myKind;
116 
118  std::string myWhat;
119 
121  const std::string myShortWhat;
122 
124  const char* myMessage;
125 
127  bool isFatal;
128 
130  static std::string parameters;
131 
132  };
133 
134 
136  class EXPORT_SYMBOLS error : public exception
137  {
138 
139  public:
140 
144  error(const char*, const char*);
146  error(const char*, const char*, LogTag);
148  error(const char*, const char*, LogTag, LogTag);
150  error(const char*, const char*, LogTag, LogTag, LogTag);
152  error(const char*, const char*, LogTag, LogTag, LogTag, LogTag);
154  error(const char*, const char*, LogTag, LogTag, LogTag, LogTag, LogTag);
156  error(const char*, const char*, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag);
158  error(const char*, const char*, std::set<LogTag>);
160 
161  };
162 
163 
165  class EXPORT_SYMBOLS warning : public exception
166  {
167 
168  public:
169 
173  warning(const char*, const char*);
175  warning(const char*, const char*, LogTag);
177  warning(const char*, const char*, LogTag, LogTag);
179  warning(const char*, const char*, LogTag, LogTag, LogTag);
181  warning(const char*, const char*, LogTag, LogTag, LogTag, LogTag);
183  warning(const char*, const char*, LogTag, LogTag, LogTag, LogTag, LogTag);
185  warning(const char*, const char*, LogTag, LogTag, LogTag, LogTag, LogTag, LogTag);
187  warning(const char*, const char*, std::set<LogTag>);
189 
190  };
191 
192 
194  class EXPORT_SYMBOLS special_exception : virtual public std::exception
195  {
196  public:
197 
199  special_exception(const char*);
200 
202  virtual ~special_exception() throw() {}
203 
205  virtual const char* what() const throw();
206 
208  std::string message();
209 
211  virtual void raise(const std::string&);
212 
215 
216  private:
217 
219  const char* myWhat;
220 
221  protected:
222 
224  std::string myMessage;
225 
226  };
227 
230  {
231 
232  private:
233 
236 
238  void abort_here_and_now();
239 
240  public:
241 
244 
246  void set_thrower(functor*);
247 
249  functor* thrower();
250 
252  virtual void raise(const std::string&);
253 
255  virtual void raise(const std::string&, int code);
256 
257  };
258 
261  {
262 
263  public:
264 
267 
268  };
269 
272  {
273 
274  public:
275 
278 
279  };
280 
283  {
284  public:
286  Piped_invalid_point() : flag(false), message("") {};
287 
289  void request(std::string message);
290 
292  void check();
293 
294  private:
295  bool flag;
296  std::string message;
297  };
298 
301 
304  {
305  public:
306  typedef std::pair<std::string,std::string> description;
308  Piped_exceptions(size_t maxExceptions) : flag(false), maxExceptions(maxExceptions) {};
309 
311  void request(std::string origin, std::string message);
312  void request(description desc);
313 
315  void check(exception &excep);
316 
318  bool inquire();
319 
321  bool inquire(std::string);
322 
323  private:
324  bool flag;
326  std::vector<description> exceptions;
327  };
328 
331 
334 
336  class SilentShutdownException : public std::exception
337  {
338  public:
340  SilentShutdownException(const std::string& message);
341  virtual const char* what() const throw();
342  private:
343  std::string myWhat;
344  };
346  class SoftShutdownException : public std::exception
347  {
348  public:
349  SoftShutdownException(const std::string& message);
350  virtual const char* what() const throw();
351  private:
352  std::string myWhat;
353  };
355  class HardShutdownException : public std::exception
356  {
357  public:
358  HardShutdownException(const std::string& message);
359  virtual const char* what() const throw();
360  private:
361  std::string myWhat;
362  };
364  class MPIShutdownException : public std::exception
365  {
366  public:
367  MPIShutdownException(const std::string& message);
368  virtual const char* what() const throw();
369  private:
370  std::string myWhat;
371  };
372 
373 }
374 
375 
376 #endif
Piped_exceptions piped_errors
Global instance of Piped_exceptions class for errors.
int invalidcode
Integer code used for exceptions.
Definition: exceptions.hpp:214
Gambit invalid loop iteration exception class.
Definition: exceptions.hpp:271
General small utility macros.
Special exception used during clean exit from diagnostics.
Definition: exceptions.hpp:336
std::string myMessage
The message passed when this exception is raised.
Definition: exceptions.hpp:224
std::pair< std::string, std::string > description
Definition: exceptions.hpp:306
Piped_exceptions(size_t maxExceptions)
Constructor.
Definition: exceptions.hpp:308
std::vector< description > exceptions
Definition: exceptions.hpp:326
#define EXPORT_SYMBOLS
Function wrapper (functor) base class.
Definition: functors.hpp:87
Piped_exceptions piped_warnings
Global instance of Piped_exceptions class for warnings.
std::set< LogTag > myLogTags
The set of tags to be passed to the logger.
Definition: exceptions.hpp:98
Piped_invalid_point()
Constructor.
Definition: exceptions.hpp:286
virtual ~exception()
Destructor.
Definition: exceptions.hpp:67
Special exception used during controlled early shutdown.
Definition: exceptions.hpp:346
Gambit invalid point exception class.
Definition: exceptions.hpp:229
Piped_invalid_point piped_invalid_point
Global instance of piped invalid point class.
Definition: exceptions.cpp:544
GAMBIT warning class.
Definition: exceptions.hpp:165
Headeer for logging classes.
Special exception raised when emergency shutdown triggered via MPI.
Definition: exceptions.hpp:364
GAMBIT error class.
Definition: exceptions.hpp:136
Special exception used during emergency early shutdown.
Definition: exceptions.hpp:355
functor * myThrower
The functor responsible for throwing this exception.
Definition: exceptions.hpp:235
GAMBIT special exception class. Not logged, meant for always catching.
Definition: exceptions.hpp:194
virtual ~special_exception()
Destructor.
Definition: exceptions.hpp:202
const char * myKind
The kind of exception (error, warning, etc; for logging).
Definition: exceptions.hpp:115
Gambit piped invalid point exception class.
Definition: exceptions.hpp:282
const std::string myShortWhat
Initial value of myWhat.
Definition: exceptions.hpp:121
static std::string parameters
Shared string indicating the current values of the paramters.
Definition: exceptions.hpp:130
std::string myWhat
What sort of exception this is (for returning with what method).
Definition: exceptions.hpp:118
bool isFatal
Flag indicating if this exception should be considered fatal or not.
Definition: exceptions.hpp:127
const char * myWhat
What this exception is (for returning with what method).
Definition: exceptions.hpp:219
Gambit halt loop exception class.
Definition: exceptions.hpp:260
const char * myMessage
The message to be logged when this exception is raised.
Definition: exceptions.hpp:124
TODO: see if we can use this one:
Definition: Analysis.hpp:33
Gambit piped error class.
Definition: exceptions.hpp:303