gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
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 
213  private:
214 
216  const char* myWhat;
217 
218  protected:
219 
221  std::string myMessage;
222 
223  };
224 
227  {
228 
229  private:
230 
233 
235  void abort_here_and_now();
236 
237  public:
238 
241 
243  void set_thrower(functor*);
244 
246  functor* thrower();
247 
249  virtual void raise(const std::string&);
250 
251  };
252 
255  {
256  public:
258  Piped_invalid_point() : flag(false), message("") {};
259 
261  void request(std::string message);
262 
264  void check();
265 
266  private:
267  bool flag;
268  std::string message;
269  };
270 
273 
276  {
277  public:
278  typedef std::pair<std::string,std::string> description;
280  Piped_exceptions(size_t maxExceptions) : flag(false), maxExceptions(maxExceptions) {};
281 
283  void request(std::string origin, std::string message);
284  void request(description desc);
285 
287  void check(exception &excep);
288 
290  bool inquire();
291 
293  bool inquire(std::string);
294 
295  private:
296  bool flag;
298  std::vector<description> exceptions;
299  };
300 
303 
306 
308  class SilentShutdownException : public std::exception
309  {
310  public:
312  SilentShutdownException(const std::string& message);
313  virtual const char* what() const throw();
314  private:
315  std::string myWhat;
316  };
318  class SoftShutdownException : public std::exception
319  {
320  public:
321  SoftShutdownException(const std::string& message);
322  virtual const char* what() const throw();
323  private:
324  std::string myWhat;
325  };
327  class HardShutdownException : public std::exception
328  {
329  public:
330  HardShutdownException(const std::string& message);
331  virtual const char* what() const throw();
332  private:
333  std::string myWhat;
334  };
336  class MPIShutdownException : public std::exception
337  {
338  public:
339  MPIShutdownException(const std::string& message);
340  virtual const char* what() const throw();
341  private:
342  std::string myWhat;
343  };
344 
345 }
346 
347 
348 #endif
Piped_exceptions piped_errors
Global instance of Piped_exceptions class for errors.
General small utility macros.
Special exception used during clean exit from diagnostics.
Definition: exceptions.hpp:308
std::string myMessage
The message passed when this exception is raised.
Definition: exceptions.hpp:221
std::pair< std::string, std::string > description
Definition: exceptions.hpp:278
Piped_exceptions(size_t maxExceptions)
Constructor.
Definition: exceptions.hpp:280
std::vector< description > exceptions
Definition: exceptions.hpp:298
#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:258
virtual ~exception()
Destructor.
Definition: exceptions.hpp:67
Special exception used during controlled early shutdown.
Definition: exceptions.hpp:318
Gambit invalid point exception class.
Definition: exceptions.hpp:226
Piped_invalid_point piped_invalid_point
Global instance of piped invalid point class.
Definition: exceptions.cpp:524
GAMBIT warning class.
Definition: exceptions.hpp:165
Headeer for logging classes.
Special exception raised when emergency shutdown triggered via MPI.
Definition: exceptions.hpp:336
GAMBIT error class.
Definition: exceptions.hpp:136
Special exception used during emergency early shutdown.
Definition: exceptions.hpp:327
functor * myThrower
The functor responsible for throwing this exception.
Definition: exceptions.hpp:232
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:254
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:216
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:275