Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
mrtError.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
23 #ifndef HEPERROR_H_INCLUDED
24 #define HEPERROR_H_INCLUDED
25 
26 #include <string>
27 #include <iostream>
28 #include <sstream>
29 #include <csignal>
30 
31 namespace mty::error{
32 
33  enum Type{
34 
35  AssertionError, //Raised when assert statement fails.
36  AttributeError, //Raised when attribute assignment or reference fails.
37  EOFError, //Raised when the input() functions hits end-of-file condition.
38  FloatingPointError, //Raised when a floating point operation fails.
39  GeneratorExit, //Raise when a generator's close() method is called.
40  ImportError, //Raised when the imported module is not found.
41  IndexError, //Raised when index of a sequence is out of range.
42  KeyError, //Raised when a key is not found in a dictionary.
43  KeyboardInterrupt, //Raised when the user hits interrupt key (Ctrl+c or delete).
44  MemoryError, //Raised when an operation runs out of memory.
45  ModelBuildingError,
46  NameError, //Raised when a variable is not found in local or global scope.
47  NotImplementedError, //Raised by abstract methods.
48  OSError, //Raised when system operation causes system related error.
49  OverflowError, //Raised when result of an arithmetic operation is too large to be represented.
50  PhysicsError,
51  ReferenceError, //Raised when a weak reference proxy is used to access a garbage collected referent.
52  RuntimeError, //Raised when an error does not fall under any other category.
53  StopIteration, //Raised by next() function to indicate that there is no further item to be returned by iterator.
54  SyntaxError, //Raised by parser when syntax error is encountered.
55  IndentationError, //Raised when there is incorrect indentation.
56  TabError, //Raised when indentation consists of inconsistent tabs and spaces.
57  SystemError, //Raised when interpreter detects internal error.
58  SystemExit, //Raised by sys.exit() function.
59  TypeError, //Raised when a function or operation is applied to an object of incorrect type.
60  UnboundLocalError, //Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable.
61  UnicodeError, //Raised when a Unicode-related encoding or decoding error occurs.
62  UnicodeEncodeError, //Raised when a Unicode-related error occurs during encoding.
63  UnicodeDecodeError, //Raised when a Unicode-related error occurs during decoding.
64  UnicodeTranslateError, //Raised when a Unicode-related error occurs during translating.
65  ValueError, //Raised when a function gets argument of correct type but improper value.
66  ZeroDivisionError //Raised when second operand of division or modulo operation is zero.
67  };
68 
69  inline std::ostream& operator<<(std::ostream& fout, mty::error::Type error)
70  {
71  switch(error) {
72  case mty::error::AssertionError: fout << "AssertionError"; break;
73  case mty::error::AttributeError: fout << "AttributeError"; break;
74  case mty::error::EOFError: fout << "EOFError"; break;
75  case mty::error::FloatingPointError: fout << "FloatingPointError"; break;
76  case mty::error::GeneratorExit: fout << "GeneratorExit"; break;
77  case mty::error::ImportError: fout << "ImportError"; break;
78  case mty::error::IndexError: fout << "IndexError"; break;
79  case mty::error::KeyError: fout << "KeyError"; break;
80  case mty::error::KeyboardInterrupt: fout << "KeyboardInterrupt"; break;
81  case mty::error::MemoryError: fout << "MemoryError"; break;
82  case mty::error::ModelBuildingError: fout << "ModelBuildingError"; break;
83  case mty::error::NameError: fout << "NameError"; break;
84  case mty::error::NotImplementedError: fout << "NotImplementedError"; break;
85  case mty::error::OSError: fout << "OSError"; break;
86  case mty::error::OverflowError: fout << "OverflowError"; break;
87  case mty::error::PhysicsError: fout << "PhysicsError"; break;
88  case mty::error::ReferenceError: fout << "ReferenceError"; break;
89  case mty::error::RuntimeError: fout << "RuntimeError"; break;
90  case mty::error::StopIteration: fout << "StopIteration"; break;
91  case mty::error::SyntaxError: fout << "SyntaxError"; break;
92  case mty::error::IndentationError: fout << "IndentationError"; break;
93  case mty::error::TabError: fout << "TabError"; break;
94  case mty::error::SystemError: fout << "SystemError"; break;
95  case mty::error::SystemExit: fout << "SystemExit"; break;
96  case mty::error::TypeError: fout << "TypeError"; break;
97  case mty::error::UnboundLocalError: fout << "UnboundLocalError"; break;
98  case mty::error::UnicodeError: fout << "UnicodeError"; break;
99  case mty::error::UnicodeEncodeError: fout << "UnicodeEncodeError"; break;
100  case mty::error::UnicodeDecodeError: fout << "UnicodeDecodeError"; break;
101  case mty::error::UnicodeTranslateError: fout << "UnicodeTranslateError"; break;
102  case mty::error::ValueError: fout << "ValueError"; break;
103  case mty::error::ZeroDivisionError: fout << "ZeroDivisionError"; break;
104  default: fout << "Type " << (int)error << "unknown!"; break;
105  }
106 
107  return fout;
108  }
109 
110 
111 } // End of namespace mty::error
112 
113 #define CallHEPError(error, spec)\
114  {\
115  std::cerr << error << " in function " << __func__ << "() (file "\
116  << __FILE__ << " l." << __LINE__ << "): " << spec << '\n';\
117  throw error;\
118  }\
119 
120 #define HEPAssert(condition, error, spec)\
121  if (not (condition)) CallHEPError(error, spec)\
122 
123 inline std::ostream& printChain(std::ostream& fout)
124 {
125  return fout;
126 }
127 
128 template<typename T, typename... G>
129 std::ostream& printChain(std::ostream& fout, T firstSpec, G... followingSpec)
130 {
131  fout << firstSpec << " ";
132  printChain(fout, followingSpec...);
133  return fout;
134 }
135 
136 #endif
Type
std::ostream & operator<<(std::ostream &fout, csl::Type type)
Definition: mrtError.h:31