|
34 | 34 | // DAMAGE.
|
35 | 35 | //
|
36 | 36 | //-----------------------------------------------------------------------------
|
37 |
| - |
38 |
| -#ifndef __CXX_Exception_h |
39 |
| -#define __CXX_Exception_h |
40 |
| - |
41 | 37 | #include "CXX/WrapPython.h"
|
42 |
| -#include "CXX/Version.hxx" |
43 |
| -#include "CXX/Config.hxx" |
44 |
| -#include "CXX/IndirectPythonInterface.hxx" |
45 |
| - |
46 |
| -#include <string> |
47 |
| -#include <iostream> |
48 |
| - |
49 |
| -// This mimics the Python structure, in order to minimize confusion |
50 |
| -namespace Py |
51 |
| -{ |
52 |
| - class ExtensionExceptionType; |
53 |
| - |
54 |
| - class Object; |
55 |
| - |
56 |
| - class Exception |
57 |
| - { |
58 |
| - public: |
59 |
| - Exception( ExtensionExceptionType &exception, const std::string& reason ); |
60 |
| - Exception( ExtensionExceptionType &exception, Object &reason ); |
61 |
| - |
62 |
| - explicit Exception () |
63 |
| - {} |
64 |
| - |
65 |
| - Exception (const std::string& reason) |
66 |
| - { |
67 |
| - PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str()); |
68 |
| - } |
69 |
| - |
70 |
| - Exception (PyObject* exception, const std::string& reason) |
71 |
| - { |
72 |
| - PyErr_SetString (exception, reason.c_str()); |
73 |
| - } |
74 |
| - |
75 |
| - Exception (PyObject* exception, Object &reason); |
76 |
| - |
77 |
| - void clear() // clear the error |
78 |
| - // technically but not philosophically const |
79 |
| - { |
80 |
| - PyErr_Clear(); |
81 |
| - } |
82 |
| - }; |
83 |
| - |
84 |
| - |
85 |
| - // Abstract |
86 |
| - class StandardError: public Exception |
87 |
| - { |
88 |
| - protected: |
89 |
| - explicit StandardError() |
90 |
| - {} |
91 |
| - }; |
92 |
| - |
93 |
| - class LookupError: public StandardError |
94 |
| - { |
95 |
| - protected: |
96 |
| - explicit LookupError() |
97 |
| - {} |
98 |
| - }; |
99 |
| - |
100 |
| - class ArithmeticError: public StandardError |
101 |
| - { |
102 |
| - protected: |
103 |
| - explicit ArithmeticError() |
104 |
| - {} |
105 |
| - }; |
106 |
| - |
107 |
| - class EnvironmentError: public StandardError |
108 |
| - { |
109 |
| - protected: |
110 |
| - explicit EnvironmentError() |
111 |
| - {} |
112 |
| - }; |
113 |
| - |
114 |
| - // Concrete |
115 |
| - |
116 |
| - class TypeError: public StandardError |
117 |
| - { |
118 |
| - public: |
119 |
| - TypeError (const std::string& reason) |
120 |
| - : StandardError() |
121 |
| - { |
122 |
| - PyErr_SetString (Py::_Exc_TypeError(),reason.c_str()); |
123 |
| - } |
124 |
| - }; |
125 |
| - |
126 |
| - class IndexError: public LookupError |
127 |
| - { |
128 |
| - public: |
129 |
| - IndexError (const std::string& reason) |
130 |
| - : LookupError() |
131 |
| - { |
132 |
| - PyErr_SetString (Py::_Exc_IndexError(), reason.c_str()); |
133 |
| - } |
134 |
| - }; |
135 |
| - |
136 |
| - class AttributeError: public StandardError |
137 |
| - { |
138 |
| - public: |
139 |
| - AttributeError (const std::string& reason) |
140 |
| - : StandardError() |
141 |
| - { |
142 |
| - PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str()); |
143 |
| - } |
144 |
| - }; |
145 |
| - |
146 |
| - class NameError: public StandardError |
147 |
| - { |
148 |
| - public: |
149 |
| - NameError (const std::string& reason) |
150 |
| - : StandardError() |
151 |
| - { |
152 |
| - PyErr_SetString (Py::_Exc_NameError(), reason.c_str()); |
153 |
| - } |
154 |
| - }; |
155 |
| - |
156 |
| - class RuntimeError: public StandardError |
157 |
| - { |
158 |
| - public: |
159 |
| - RuntimeError (const std::string& reason) |
160 |
| - : StandardError() |
161 |
| - { |
162 |
| - PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str()); |
163 |
| - } |
164 |
| - }; |
165 |
| - |
166 |
| - class SystemError: public StandardError |
167 |
| - { |
168 |
| - public: |
169 |
| - SystemError (const std::string& reason) |
170 |
| - : StandardError() |
171 |
| - { |
172 |
| - PyErr_SetString (Py::_Exc_SystemError(),reason.c_str()); |
173 |
| - } |
174 |
| - }; |
175 |
| - |
176 |
| - class KeyError: public LookupError |
177 |
| - { |
178 |
| - public: |
179 |
| - KeyError (const std::string& reason) |
180 |
| - : LookupError() |
181 |
| - { |
182 |
| - PyErr_SetString (Py::_Exc_KeyError(),reason.c_str()); |
183 |
| - } |
184 |
| - }; |
185 |
| - |
186 |
| - |
187 |
| - class ValueError: public StandardError |
188 |
| - { |
189 |
| - public: |
190 |
| - ValueError (const std::string& reason) |
191 |
| - : StandardError() |
192 |
| - { |
193 |
| - PyErr_SetString (Py::_Exc_ValueError(), reason.c_str()); |
194 |
| - } |
195 |
| - }; |
196 |
| - |
197 |
| - class OverflowError: public ArithmeticError |
198 |
| - { |
199 |
| - public: |
200 |
| - OverflowError (const std::string& reason) |
201 |
| - : ArithmeticError() |
202 |
| - { |
203 |
| - PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str()); |
204 |
| - } |
205 |
| - }; |
206 |
| - |
207 |
| - class ZeroDivisionError: public ArithmeticError |
208 |
| - { |
209 |
| - public: |
210 |
| - ZeroDivisionError (const std::string& reason) |
211 |
| - : ArithmeticError() |
212 |
| - { |
213 |
| - PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str()); |
214 |
| - } |
215 |
| - }; |
216 |
| - |
217 |
| - class FloatingPointError: public ArithmeticError |
218 |
| - { |
219 |
| - public: |
220 |
| - FloatingPointError (const std::string& reason) |
221 |
| - : ArithmeticError() |
222 |
| - { |
223 |
| - PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str()); |
224 |
| - } |
225 |
| - }; |
226 |
| - |
227 |
| - class MemoryError: public StandardError |
228 |
| - { |
229 |
| - public: |
230 |
| - MemoryError (const std::string& reason) |
231 |
| - : StandardError() |
232 |
| - { |
233 |
| - PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str()); |
234 |
| - } |
235 |
| - }; |
236 |
| - |
237 |
| - class SystemExit: public StandardError |
238 |
| - { |
239 |
| - public: |
240 |
| - SystemExit (const std::string& reason) |
241 |
| - : StandardError() |
242 |
| - { |
243 |
| - PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str()); |
244 |
| - } |
245 |
| - }; |
246 |
| - |
247 |
| -}// Py |
248 | 38 |
|
| 39 | +#if PY_MAJOR_VERSION == 2 |
| 40 | +#include "CXX/Python2/Exception.hxx" |
| 41 | +#else |
| 42 | +#include "CXX/Python3/Exception.hxx" |
249 | 43 | #endif
|
0 commit comments