Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Exceptions.hh
Go to the documentation of this file.
1 ///
2 /// @file Exceptions.hh
3 /// @brief Hammer exception definitions
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #ifndef HAMMER_EXCEPTIONS
13 #define HAMMER_EXCEPTIONS
14 
15 #include <exception>
16 #include <stdexcept>
17 #include <string>
18 
19 namespace Hammer {
20 
21  /// @brief Generic error class
22  /// @ingroup Base
23  class Error : public std::runtime_error {
24 
25  public:
26  Error(const std::string& message) noexcept : runtime_error(message) {
27  }
28 
29  Error(const Error&) = default;
30  Error(Error&&) = default;
31  Error& operator=(const Error&) = default;
32  Error& operator=(Error&&) = default;
33  virtual ~Error() noexcept { }
34 
35  };
36 
37  /// @brief Invalid index label error class
38  /// @ingroup Base
39  class IndexLabelError : public Error {
40 
41  public:
42  IndexLabelError(const std::string& message) noexcept : Error(message) {
43  }
44 
45  };
46 
47  /// @brief Out-of-range error class
48  /// @ingroup Base
49  class RangeError : public Error {
50 
51  public:
52  RangeError(const std::string& message) noexcept : Error(message) {
53  }
54 
55  };
56 
57  /// @brief Invalid phase space point error class
58  /// @ingroup Base
59  class PhaseSpaceError : public Error {
60 
61  public:
62  PhaseSpaceError(const std::string& message) noexcept : Error(message) {
63  }
64 
65  };
66 
67  /// @brief Initialization error class
68  /// @ingroup Base
69  class InitializationError : public Error {
70 
71  public:
72  InitializationError(const std::string& message) noexcept : Error(message) {
73  }
74 
75  };
76 
77 } // namespace Hammer
78 
79 namespace Assert {
80  void HandleAssert(const char *message,
81  const char *condition,
82  const char *fileName,
83  long lineNumber);
84 }
85 
86 #ifndef NDEBUG
87 
88  #define ASSERT_MSG(x, msg) do{ \
89  if(!(x)) {\
90  Assert::HandleAssert(msg, #x, __FILE__, __LINE__); \
91  abort(); \
92  }\
93  } while(0)
94 
95  #define ASSERT(x) do{ \
96  if(!(x)) {\
97  Assert::HandleAssert("Assertion!", #x, __FILE__, __LINE__); \
98  abort(); \
99  }\
100  } while(0)
101 
102 #else // Disabled Asserts
103 
104  #define ASSERT(x) do { (void)sizeof(true); } while(0)
105 
106  #define ASSERT_MSG(x, msg) do { (void)sizeof(true), (void)sizeof(msg); } while(0)
107 
108 #endif
109 
110 #endif
PhaseSpaceError(const std::string &message) noexcept
Definition: Exceptions.hh:62
IndexLabelError(const std::string &message) noexcept
Definition: Exceptions.hh:42
InitializationError(const std::string &message) noexcept
Definition: Exceptions.hh:72
Invalid phase space point error class.
Definition: Exceptions.hh:59
Error(const std::string &message) noexcept
Definition: Exceptions.hh:26
Initialization error class.
Definition: Exceptions.hh:69
Invalid index label error class.
Definition: Exceptions.hh:39
Generic error class.
Definition: Exceptions.hh:23
Error & operator=(const Error &)=default
RangeError(const std::string &message) noexcept
Definition: Exceptions.hh:52
void HandleAssert(const char *message, const char *condition, const char *fileName, long lineNumber)
Definition: Errors.cc:20
virtual ~Error() noexcept
Definition: Exceptions.hh:33
Out-of-range error class.
Definition: Exceptions.hh:49