Mantid
Loading...
Searching...
No Matches
Exception.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidKernel/DllConfig.h"
9#include <sstream>
10#include <utility>
11
13//-------------------------
14// FileError
15//-------------------------
20FileError::FileError(const std::string &Desc, std::string FName)
21 : std::runtime_error(Desc), fileName(std::move(FName)) {
22 outMessage = std::string(std::runtime_error::what()) + " in \"" + fileName + "\"";
23}
24
26FileError::FileError(const FileError &A) : std::runtime_error(A), fileName(A.fileName) {}
27
31const char *FileError::what() const noexcept { return outMessage.c_str(); }
32
33//-------------------------
34// ParseError
35//-------------------------
36ParseError::ParseError(const std::string &desc, const std::string &fileName, const int &lineNumber)
37 : FileError(desc, fileName), m_lineNumber(lineNumber) {
38 std::stringstream ss;
39 ss << FileError::what() << " on line " << m_lineNumber;
40 m_outMessage = ss.str();
41}
42
43ParseError::ParseError(const ParseError &A) : FileError(A), m_lineNumber(A.m_lineNumber) {}
44
45const char *ParseError::what() const noexcept { return m_outMessage.c_str(); }
46
47//-------------------------
48// NotImplementedError
49//-------------------------
53NotImplementedError::NotImplementedError(const std::string &Desc) : std::logic_error(Desc) {}
54
58const char *NotImplementedError::what() const noexcept { return std::logic_error::what(); }
59
60//-------------------------
61// NotFoundError
62//-------------------------
67NotFoundError::NotFoundError(const std::string &Desc, std::string ObjectName)
68 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
69 outMessage = std::string(std::runtime_error::what()) + " search object '" + objectName + "'";
70}
71
76NotFoundError::NotFoundError(const std::string &Desc, const int &ObjectNum) : std::runtime_error(Desc) {
77 std::stringstream ss;
78 std::string obName;
79 ss << ObjectNum;
80 ss >> obName;
81 outMessage = std::string(std::runtime_error::what()) + " search object '" + obName + "'";
82}
83
84NotFoundError::NotFoundError(const std::string &Desc, const int64_t &ObjectNum) : std::runtime_error(Desc) {
85 std::stringstream ss;
86 std::string obName;
87 ss << ObjectNum;
88 ss >> obName;
89 outMessage = std::string(std::runtime_error::what()) + " search object '" + obName + "'";
90}
91
92NotFoundError::NotFoundError(const std::string &Desc, const std::size_t &ObjectNum) : std::runtime_error(Desc) {
93 std::stringstream ss;
94 std::string obName;
95 ss << ObjectNum;
96 ss >> obName;
97 outMessage = std::string(std::runtime_error::what()) + " search object '" + obName + "'";
98}
99
101NotFoundError::NotFoundError(const NotFoundError &A) : std::runtime_error(A), objectName(A.objectName) {}
102
106const char *NotFoundError::what() const noexcept { return outMessage.c_str(); }
107
108//-------------------------
109// ExistsError
110//-------------------------
115ExistsError::ExistsError(const std::string &Desc, std::string ObjectName)
116 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
117 outMessage = std::string(std::runtime_error::what()) + " search object '" + objectName + "'";
118}
119
121ExistsError::ExistsError(const ExistsError &A) : std::runtime_error(A), objectName(A.objectName) {}
122
126const char *ExistsError::what() const noexcept { return outMessage.c_str(); }
127
128//-------------------------
129// AbsObjMethod
130//-------------------------
134AbsObjMethod::AbsObjMethod(std::string ObjectName) : std::runtime_error(""), objectName(std::move(ObjectName)) {
135 outMessage = std::string("AbsObjMethod object: ") + objectName;
136}
137
139AbsObjMethod::AbsObjMethod(const AbsObjMethod &A) : std::runtime_error(A), objectName(A.objectName) {}
140
144const char *AbsObjMethod::what() const noexcept { return outMessage.c_str(); }
145
146//-------------------------
147// InstrumentDefinitionError
148//-------------------------
153InstrumentDefinitionError::InstrumentDefinitionError(const std::string &Desc, std::string ObjectName)
154 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
155 outMessage = std::string(std::runtime_error::what()) + " while searching for " + objectName +
156 ". See http://docs.mantidproject.org/concepts/InstrumentDefinitionFile for IDF syntax.";
157}
158
162InstrumentDefinitionError::InstrumentDefinitionError(const std::string &Desc) : std::runtime_error(Desc) {
163 outMessage = std::string(std::runtime_error::what());
164}
165
168 : std::runtime_error(A), objectName(A.objectName) {}
169
173const char *InstrumentDefinitionError::what() const noexcept { return outMessage.c_str(); }
174
175//-------------------------
176// OpenGLError
177//-------------------------
182OpenGLError::OpenGLError(const std::string &Desc, std::string ObjectName)
183 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
184 outMessage = std::string(std::runtime_error::what()) + " rendering " + objectName;
185}
186
190OpenGLError::OpenGLError(const std::string &Desc) : std::runtime_error(Desc) {
191 outMessage = std::string(std::runtime_error::what());
192}
193
195OpenGLError::OpenGLError(const OpenGLError &A) : std::runtime_error(A), objectName(A.objectName) {}
196
200const char *OpenGLError::what() const noexcept { return outMessage.c_str(); }
201
202//-------------------------
203// MisMatch
204//-------------------------
205
206template <typename T>
207MisMatch<T>::MisMatch(const T &A, const T &B, const std::string &Place)
208 : std::runtime_error(Place), Aval(A), Bval(B)
215{
216 std::stringstream cx;
217 cx << Place << " Item A!=B " << Aval << " " << Bval << " ";
218 m_message = cx.str();
219}
220
221template <typename T>
223 : std::runtime_error(A), Aval(A.Aval), Bval(A.Bval)
228{}
229
230template <typename T>
231const char *MisMatch<T>::what() const noexcept
236{
237 return m_message.c_str();
238}
239
241template class MANTID_KERNEL_DLL MisMatch<int>;
242template class MANTID_KERNEL_DLL MisMatch<size_t>;
244
245//-------------------------
246// Index Error class
247//-------------------------
248
255IndexError::IndexError(const size_t V, const size_t B, const std::string &Place)
256 : std::runtime_error(Place), Val(V), maxVal(B) {
257 std::stringstream cx;
258 cx << "IndexError: " << Place << " " << Val << " :: 0 <==> " << maxVal;
259 m_message = cx.str();
260}
261
266IndexError::IndexError(const IndexError &A) : std::runtime_error(A), Val(A.Val), maxVal(A.maxVal) {}
267
272const char *IndexError::what() const noexcept { return m_message.c_str(); }
273
274//-------------------------
275// NullPointerException class
276//-------------------------
277
282NullPointerException::NullPointerException(const std::string &place, const std::string &objectName)
283 : std::runtime_error(place),
284 outMessage("Attempt to dereference zero pointer (" + objectName + ") in function " + place) {}
285
286const char *NullPointerException::what() const noexcept { return outMessage.c_str(); }
287
288//-------------------------
289// InternetError Error class
290//-------------------------
291
297InternetError::InternetError(const std::string &message, const int &errorCode) : std::runtime_error(message) {
298 std::stringstream cx;
299 cx << "InternetError: ";
300 if (errorCode != 0) {
301 cx << "[" << errorCode << "] ";
302 }
303 cx << message;
304 outMessage = cx.str();
306}
307
312const char *InternetError::what() const noexcept { return outMessage.c_str(); }
313
318const int &InternetError::errorCode() const { return m_errorCode; }
319
320//-------------------------
321// FitSizeError Error class
322//-------------------------
323
327 : std::exception(),
328 m_message("Number of fitting parameters is different from original value of " + std::to_string(oldSize)) {}
329
333FitSizeWarning::FitSizeWarning(size_t oldSize, size_t newSize)
334 : std::exception(), m_message("Number of fitting parameters changed from " + std::to_string(oldSize) + " to " +
335 std::to_string(newSize)) {}
336
338const char *FitSizeWarning::what() const noexcept { return m_message.c_str(); }
339
340} // namespace Mantid::Kernel::Exception
Exception for a call to an abstract class function.
Definition Exception.h:202
std::string outMessage
The message returned by what()
Definition Exception.h:207
const std::string objectName
The name of the search object.
Definition Exception.h:205
AbsObjMethod(std::string)
Constructor.
const char * what() const noexcept override
Writes out the range and limits.
Exception for when an item is already in a collection.
Definition Exception.h:164
std::string outMessage
The message returned by what()
Definition Exception.h:169
const std::string objectName
The name of the search object.
Definition Exception.h:167
ExistsError(const std::string &, std::string)
Constructor.
const char * what() const noexcept override
Writes out the range and limits.
Records the filename and the description of failure.
Definition Exception.h:98
const std::string fileName
The name of the file relating to the error.
Definition Exception.h:101
FileError(const std::string &Desc, std::string FName)
Constructor.
Definition Exception.cpp:20
std::string outMessage
The message returned by what()
Definition Exception.h:103
const char * what() const noexcept override
Writes out the range and limits.
Definition Exception.cpp:31
FitSizeWarning(size_t oldSize)
Constructor.
const char * what() const noexcept override
Get the warning message.
Exception for index errors.
Definition Exception.h:284
const char * what() const noexcept override
Overloaded reporting method.
const size_t Val
Actual value called.
Definition Exception.h:286
const size_t maxVal
Maximum value.
Definition Exception.h:287
IndexError(const size_t V, const size_t B, const std::string &Place)
Constructor.
std::string m_message
The message reported by what()
Definition Exception.h:288
Exception for errors associated with the instrument definition.
Definition Exception.h:220
const char * what() const noexcept override
Writes out the range and limits.
std::string outMessage
The message returned by what()
Definition Exception.h:225
InstrumentDefinitionError(const std::string &, std::string)
Constructor.
const std::string objectName
The name of the search object.
Definition Exception.h:223
const char * what() const noexcept override
Overloaded reporting method.
InternetError(const std::string &message, const int &errorCode=0)
Constructor.
const int & errorCode() const
Writes out the range and limits.
int m_errorCode
The message reported by what()
Definition Exception.h:325
std::string outMessage
The message returned by what()
Definition Exception.h:324
Error when two numbers should be identical (or close)
Definition Exception.h:263
std::string m_message
The message reported by what()
Definition Exception.h:267
const char * what() const noexcept override
Overloaded reporting method.
MisMatch(const T &, const T &, const std::string &)
Constructor store two mismatched items.
Exception for when an item is not found in a collection.
Definition Exception.h:145
const char * what() const noexcept override
Writes out the range and limits.
NotFoundError(const std::string &, std::string)
Constructor.
Definition Exception.cpp:67
std::string outMessage
The message returned by what()
Definition Exception.h:150
const std::string objectName
The name of the search object.
Definition Exception.h:148
NotImplementedError(const std::string &)
Constructor.
Definition Exception.cpp:53
const char * what() const noexcept override
Writes out the range and limits.
Definition Exception.cpp:58
const char * what() const noexcept override
Overloaded reporting method.
const std::string outMessage
The message returned by what()
Definition Exception.h:308
NullPointerException(const std::string &place, const std::string &objectName)
Constructor.
const char * what() const noexcept override
Writes out the range and limits.
std::string outMessage
The message returned by what()
Definition Exception.h:245
const std::string objectName
The name of the search object.
Definition Exception.h:243
OpenGLError(const std::string &, std::string)
Constructor.
Records the filename, the description of failure and the line on which it happened.
Definition Exception.h:115
ParseError(const std::string &desc, const std::string &fileName, const int &lineNumber)
Constructor.
Definition Exception.cpp:36
const int m_lineNumber
Number of the line where the error occured.
Definition Exception.h:118
const char * what() const noexcept override
Definition Exception.cpp:45
std::string m_outMessage
The message returned by what()
Definition Exception.h:120
The exception classes used by Mantid.
Definition Exception.h:95
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)