forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exception.cpp
349 lines (299 loc) · 11.1 KB
/
Exception.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidKernel/Exception.h"
#include <sstream>
namespace Mantid {
namespace Kernel {
namespace Exception {
//-------------------------
// FileError
//-------------------------
/** Constructor
@param Desc :: Function description
@param FName :: Filename
*/
FileError::FileError(const std::string &Desc, const std::string &FName) : std::runtime_error(Desc), fileName(FName) {
outMessage = std::string(std::runtime_error::what()) + " in \"" + fileName + "\"";
}
/// Copy constructor
FileError::FileError(const FileError &A) : std::runtime_error(A), fileName(A.fileName) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *FileError::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// ParseError
//-------------------------
ParseError::ParseError(const std::string &desc, const std::string &fileName, const int &lineNumber)
: FileError(desc, fileName), m_lineNumber(lineNumber) {
std::stringstream ss;
ss << FileError::what() << " on line " << m_lineNumber;
m_outMessage = ss.str();
}
ParseError::ParseError(const ParseError &A) : FileError(A), m_lineNumber(A.m_lineNumber) {}
const char *ParseError::what() const noexcept { return m_outMessage.c_str(); }
//-------------------------
// NotImplementedError
//-------------------------
/** Constructor
@param Desc :: Function description
*/
NotImplementedError::NotImplementedError(const std::string &Desc) : std::logic_error(Desc) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *NotImplementedError::what() const noexcept { return std::logic_error::what(); }
//-------------------------
// NotFoundError
//-------------------------
/** Constructor
@param Desc :: Function description
@param ObjectName :: The name of the search object
*/
NotFoundError::NotFoundError(const std::string &Desc, const std::string &ObjectName)
: std::runtime_error(Desc), objectName(ObjectName) {
outMessage = std::string(std::runtime_error::what()) + " search object " + objectName;
}
/** Constructor
@param Desc :: Function description
@param ObjectNum :: The integer search object
*/
NotFoundError::NotFoundError(const std::string &Desc, const int &ObjectNum) : std::runtime_error(Desc) {
std::stringstream ss;
std::string obName;
ss << ObjectNum;
ss >> obName;
outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
}
NotFoundError::NotFoundError(const std::string &Desc, const int64_t &ObjectNum) : std::runtime_error(Desc) {
std::stringstream ss;
std::string obName;
ss << ObjectNum;
ss >> obName;
outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
}
NotFoundError::NotFoundError(const std::string &Desc, const std::size_t &ObjectNum) : std::runtime_error(Desc) {
std::stringstream ss;
std::string obName;
ss << ObjectNum;
ss >> obName;
outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
}
/// Copy constructor
NotFoundError::NotFoundError(const NotFoundError &A) : std::runtime_error(A), objectName(A.objectName) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *NotFoundError::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// ExistsError
//-------------------------
/** Constructor
@param Desc :: Function description
@param ObjectName :: The name of the search object
*/
ExistsError::ExistsError(const std::string &Desc, const std::string &ObjectName)
: std::runtime_error(Desc), objectName(ObjectName) {
outMessage = std::string(std::runtime_error::what()) + " search object " + objectName;
}
/// Copy constructor
ExistsError::ExistsError(const ExistsError &A) : std::runtime_error(A), objectName(A.objectName) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *ExistsError::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// AbsObjMethod
//-------------------------
/** Constructor
@param ObjectName :: The name of the search object
*/
AbsObjMethod::AbsObjMethod(const std::string &ObjectName) : std::runtime_error(""), objectName(ObjectName) {
outMessage = std::string("AbsObjMethod object: ") + objectName;
}
/// Copy constructor
AbsObjMethod::AbsObjMethod(const AbsObjMethod &A) : std::runtime_error(A), objectName(A.objectName) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *AbsObjMethod::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// InstrumentDefinitionError
//-------------------------
/** Constructor
@param Desc :: Function description
@param ObjectName :: The name of the search object
*/
InstrumentDefinitionError::InstrumentDefinitionError(const std::string &Desc, const std::string &ObjectName)
: std::runtime_error(Desc), objectName(ObjectName) {
outMessage = std::string(std::runtime_error::what()) + " search object " + objectName +
". See http://www.mantidproject.org/IDF for IDF syntax.";
}
/** Constructor
@param Desc :: Function description
*/
InstrumentDefinitionError::InstrumentDefinitionError(const std::string &Desc) : std::runtime_error(Desc) {
outMessage = std::string(std::runtime_error::what());
}
/// Copy constructor
InstrumentDefinitionError::InstrumentDefinitionError(const InstrumentDefinitionError &A)
: std::runtime_error(A), objectName(A.objectName) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *InstrumentDefinitionError::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// OpenGLError
//-------------------------
/** Constructor
@param Desc :: Function description
@param ObjectName :: The name of the search object
*/
OpenGLError::OpenGLError(const std::string &Desc, const std::string &ObjectName)
: std::runtime_error(Desc), objectName(ObjectName) {
outMessage = std::string(std::runtime_error::what()) + " rendering " + objectName;
}
/** Constructor
@param Desc :: Function description
*/
OpenGLError::OpenGLError(const std::string &Desc) : std::runtime_error(Desc) {
outMessage = std::string(std::runtime_error::what());
}
/// Copy constructor
OpenGLError::OpenGLError(const OpenGLError &A) : std::runtime_error(A), objectName(A.objectName) {}
/** Writes out the range and limits
@returns a char array of foramtted error information
*/
const char *OpenGLError::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// MisMatch
//-------------------------
template <typename T>
MisMatch<T>::MisMatch(const T &A, const T &B, const std::string &Place)
: std::runtime_error(Place), Aval(A), Bval(B)
/**
Constructor store two mismatched items
@param A :: Item to store
@param B :: Item to store
@param Place :: Reason/Code item for error
*/
{
std::stringstream cx;
cx << Place << " Item A!=B " << Aval << " " << Bval << " ";
m_message = cx.str();
}
template <typename T>
MisMatch<T>::MisMatch(const MisMatch<T> &A)
: std::runtime_error(A), Aval(A.Aval), Bval(A.Bval)
/**
Copy Constructor
@param A :: MisMatch to copy
*/
{}
template <typename T> MisMatch<T> &MisMatch<T>::operator=(const MisMatch<T> & /*unused*/) {
/**
Copy assignment
@param rhs :: MisMatch to copy
*/
throw NotImplementedError("MisMatch<T>::operator=");
}
template <typename T>
const char *MisMatch<T>::what() const noexcept
/**
Writes out the two mismatched items
@return String description of error
*/
{
return m_message.c_str();
}
/// \cond TEMPLATE
template class DLLExport MisMatch<int>;
template class DLLExport MisMatch<size_t>;
/// \endcond TEMPLATE
//-------------------------
// Index Error class
//-------------------------
/**
Constructor
@param V :: Value of index
@param B :: Maximum value
@param Place :: Location of Error
*/
IndexError::IndexError(const size_t V, const size_t B, const std::string &Place)
: std::runtime_error(Place), Val(V), maxVal(B) {
std::stringstream cx;
cx << "IndexError: " << Place << " " << Val << " :: 0 <==> " << maxVal;
m_message = cx.str();
}
/**
Copy Constructor
@param A :: IndexError to copy
*/
IndexError::IndexError(const IndexError &A) : std::runtime_error(A), Val(A.Val), maxVal(A.maxVal) {}
/**
Writes out the range and limits
@return the error string
*/
const char *IndexError::what() const noexcept { return m_message.c_str(); }
//-------------------------
// NullPointerException class
//-------------------------
/** Constructor
* @param place :: The class & function where the exception occurred
* @param objectName :: The name of the pointer
*/
NullPointerException::NullPointerException(const std::string &place, const std::string &objectName)
: std::runtime_error(place),
outMessage("Attempt to dereference zero pointer (" + objectName + ") in function " + place) {}
const char *NullPointerException::what() const noexcept { return outMessage.c_str(); }
//-------------------------
// InternetError Error class
//-------------------------
/**
Constructor
@param message :: The error message
@param errorCode :: The HTTP error code if available
*/
InternetError::InternetError(const std::string &message, const int &errorCode) : std::runtime_error(message) {
std::stringstream cx;
cx << "InternetError: ";
if (errorCode != 0) {
cx << "[" << errorCode << "] ";
}
cx << message;
outMessage = cx.str();
m_errorCode = errorCode;
}
/**
Writes out the range and limits
@return the error string
*/
const char *InternetError::what() const noexcept { return outMessage.c_str(); }
/**
Writes out the range and limits
@return the error string
*/
const int &InternetError::errorCode() const { return m_errorCode; }
//-------------------------
// FitSizeError Error class
//-------------------------
/// Constructor.
/// @param oldSize :: Old number of free fitting parameters
FitSizeWarning::FitSizeWarning(size_t oldSize)
: std::exception(),
m_message("Number of fitting parameters is different from original value of " + std::to_string(oldSize)) {}
/// Constructor.
/// @param oldSize :: Old number of free fitting parameters
/// @param newSize :: New number of free fitting parameters
FitSizeWarning::FitSizeWarning(size_t oldSize, size_t newSize)
: std::exception(), m_message("Number of fitting parameters changed from " + std::to_string(oldSize) + " to " +
std::to_string(newSize)) {}
/// Get the warning message.
const char *FitSizeWarning::what() const noexcept { return m_message.c_str(); }
} // namespace Exception
} // namespace Kernel
} // namespace Mantid