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 <sstream>
9#include <utility>
10
12//-------------------------
13// FileError
14//-------------------------
19FileError::FileError(const std::string &Desc, std::string FName)
20 : std::runtime_error(Desc), fileName(std::move(FName)) {
21 outMessage = std::string(std::runtime_error::what()) + " in \"" + fileName + "\"";
22}
23
25FileError::FileError(const FileError &A) : std::runtime_error(A), fileName(A.fileName) {}
26
30const char *FileError::what() const noexcept { return outMessage.c_str(); }
31
32//-------------------------
33// ParseError
34//-------------------------
35ParseError::ParseError(const std::string &desc, const std::string &fileName, const int &lineNumber)
36 : FileError(desc, fileName), m_lineNumber(lineNumber) {
37 std::stringstream ss;
38 ss << FileError::what() << " on line " << m_lineNumber;
39 m_outMessage = ss.str();
40}
41
42ParseError::ParseError(const ParseError &A) : FileError(A), m_lineNumber(A.m_lineNumber) {}
43
44const char *ParseError::what() const noexcept { return m_outMessage.c_str(); }
45
46//-------------------------
47// NotImplementedError
48//-------------------------
52NotImplementedError::NotImplementedError(const std::string &Desc) : std::logic_error(Desc) {}
53
57const char *NotImplementedError::what() const noexcept { return std::logic_error::what(); }
58
59//-------------------------
60// NotFoundError
61//-------------------------
66NotFoundError::NotFoundError(const std::string &Desc, std::string ObjectName)
67 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
68 outMessage = std::string(std::runtime_error::what()) + " search object " + objectName;
69}
70
75NotFoundError::NotFoundError(const std::string &Desc, const int &ObjectNum) : std::runtime_error(Desc) {
76 std::stringstream ss;
77 std::string obName;
78 ss << ObjectNum;
79 ss >> obName;
80 outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
81}
82
83NotFoundError::NotFoundError(const std::string &Desc, const int64_t &ObjectNum) : std::runtime_error(Desc) {
84 std::stringstream ss;
85 std::string obName;
86 ss << ObjectNum;
87 ss >> obName;
88 outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
89}
90
91NotFoundError::NotFoundError(const std::string &Desc, const std::size_t &ObjectNum) : std::runtime_error(Desc) {
92 std::stringstream ss;
93 std::string obName;
94 ss << ObjectNum;
95 ss >> obName;
96 outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
97}
98
100NotFoundError::NotFoundError(const NotFoundError &A) : std::runtime_error(A), objectName(A.objectName) {}
101
105const char *NotFoundError::what() const noexcept { return outMessage.c_str(); }
106
107//-------------------------
108// ExistsError
109//-------------------------
114ExistsError::ExistsError(const std::string &Desc, std::string ObjectName)
115 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
116 outMessage = std::string(std::runtime_error::what()) + " search object " + objectName;
117}
118
120ExistsError::ExistsError(const ExistsError &A) : std::runtime_error(A), objectName(A.objectName) {}
121
125const char *ExistsError::what() const noexcept { return outMessage.c_str(); }
126
127//-------------------------
128// AbsObjMethod
129//-------------------------
133AbsObjMethod::AbsObjMethod(std::string ObjectName) : std::runtime_error(""), objectName(std::move(ObjectName)) {
134 outMessage = std::string("AbsObjMethod object: ") + objectName;
135}
136
138AbsObjMethod::AbsObjMethod(const AbsObjMethod &A) : std::runtime_error(A), objectName(A.objectName) {}
139
143const char *AbsObjMethod::what() const noexcept { return outMessage.c_str(); }
144
145//-------------------------
146// InstrumentDefinitionError
147//-------------------------
152InstrumentDefinitionError::InstrumentDefinitionError(const std::string &Desc, std::string ObjectName)
153 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
154 outMessage = std::string(std::runtime_error::what()) + " search object " + objectName +
155 ". See http://www.mantidproject.org/IDF for IDF syntax.";
156}
157
161InstrumentDefinitionError::InstrumentDefinitionError(const std::string &Desc) : std::runtime_error(Desc) {
162 outMessage = std::string(std::runtime_error::what());
163}
164
167 : std::runtime_error(A), objectName(A.objectName) {}
168
172const char *InstrumentDefinitionError::what() const noexcept { return outMessage.c_str(); }
173
174//-------------------------
175// OpenGLError
176//-------------------------
181OpenGLError::OpenGLError(const std::string &Desc, std::string ObjectName)
182 : std::runtime_error(Desc), objectName(std::move(ObjectName)) {
183 outMessage = std::string(std::runtime_error::what()) + " rendering " + objectName;
184}
185
189OpenGLError::OpenGLError(const std::string &Desc) : std::runtime_error(Desc) {
190 outMessage = std::string(std::runtime_error::what());
191}
192
194OpenGLError::OpenGLError(const OpenGLError &A) : std::runtime_error(A), objectName(A.objectName) {}
195
199const char *OpenGLError::what() const noexcept { return outMessage.c_str(); }
200
201//-------------------------
202// MisMatch
203//-------------------------
204
205template <typename T>
206MisMatch<T>::MisMatch(const T &A, const T &B, const std::string &Place)
207 : std::runtime_error(Place), Aval(A), Bval(B)
214{
215 std::stringstream cx;
216 cx << Place << " Item A!=B " << Aval << " " << Bval << " ";
217 m_message = cx.str();
218}
219
220template <typename T>
222 : std::runtime_error(A), Aval(A.Aval), Bval(A.Bval)
227{}
228
229template <typename T>
230const char *MisMatch<T>::what() const noexcept
235{
236 return m_message.c_str();
237}
238
240template class DLLExport MisMatch<int>;
241template class DLLExport MisMatch<size_t>;
243
244//-------------------------
245// Index Error class
246//-------------------------
247
254IndexError::IndexError(const size_t V, const size_t B, const std::string &Place)
255 : std::runtime_error(Place), Val(V), maxVal(B) {
256 std::stringstream cx;
257 cx << "IndexError: " << Place << " " << Val << " :: 0 <==> " << maxVal;
258 m_message = cx.str();
259}
260
265IndexError::IndexError(const IndexError &A) : std::runtime_error(A), Val(A.Val), maxVal(A.maxVal) {}
266
271const char *IndexError::what() const noexcept { return m_message.c_str(); }
272
273//-------------------------
274// NullPointerException class
275//-------------------------
276
281NullPointerException::NullPointerException(const std::string &place, const std::string &objectName)
282 : std::runtime_error(place),
283 outMessage("Attempt to dereference zero pointer (" + objectName + ") in function " + place) {}
284
285const char *NullPointerException::what() const noexcept { return outMessage.c_str(); }
286
287//-------------------------
288// InternetError Error class
289//-------------------------
290
296InternetError::InternetError(const std::string &message, const int &errorCode) : std::runtime_error(message) {
297 std::stringstream cx;
298 cx << "InternetError: ";
299 if (errorCode != 0) {
300 cx << "[" << errorCode << "] ";
301 }
302 cx << message;
303 outMessage = cx.str();
305}
306
311const char *InternetError::what() const noexcept { return outMessage.c_str(); }
312
317const int &InternetError::errorCode() const { return m_errorCode; }
318
319//-------------------------
320// FitSizeError Error class
321//-------------------------
322
326 : std::exception(),
327 m_message("Number of fitting parameters is different from original value of " + std::to_string(oldSize)) {}
328
332FitSizeWarning::FitSizeWarning(size_t oldSize, size_t newSize)
333 : std::exception(), m_message("Number of fitting parameters changed from " + std::to_string(oldSize) + " to " +
334 std::to_string(newSize)) {}
335
337const char *FitSizeWarning::what() const noexcept { return m_message.c_str(); }
338
339} // namespace Mantid::Kernel::Exception
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
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.
Definition: Exception.cpp:133
const char * what() const noexcept override
Writes out the range and limits.
Definition: Exception.cpp:143
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.
Definition: Exception.cpp:114
const char * what() const noexcept override
Writes out the range and limits.
Definition: Exception.cpp:125
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:19
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:30
FitSizeWarning(size_t oldSize)
Constructor.
Definition: Exception.cpp:325
const char * what() const noexcept override
Get the warning message.
Definition: Exception.cpp:337
Exception for index errors.
Definition: Exception.h:284
const char * what() const noexcept override
Overloaded reporting method.
Definition: Exception.cpp:271
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.
Definition: Exception.cpp:254
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.
Definition: Exception.cpp:172
std::string outMessage
The message returned by what()
Definition: Exception.h:225
InstrumentDefinitionError(const std::string &, std::string)
Constructor.
Definition: Exception.cpp:152
const std::string objectName
The name of the search object.
Definition: Exception.h:223
const char * what() const noexcept override
Overloaded reporting method.
Definition: Exception.cpp:311
InternetError(const std::string &message, const int &errorCode=0)
Constructor.
Definition: Exception.cpp:296
const int & errorCode() const
Writes out the range and limits.
Definition: Exception.cpp:317
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.
Definition: Exception.cpp:230
MisMatch(const T &, const T &, const std::string &)
Constructor store two mismatched items.
Definition: Exception.cpp:206
const T Bval
container size
Definition: Exception.h:266
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.
Definition: Exception.cpp:105
NotFoundError(const std::string &, std::string)
Constructor.
Definition: Exception.cpp:66
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:52
const char * what() const noexcept override
Writes out the range and limits.
Definition: Exception.cpp:57
const char * what() const noexcept override
Overloaded reporting method.
Definition: Exception.cpp:285
const std::string outMessage
The message returned by what()
Definition: Exception.h:308
NullPointerException(const std::string &place, const std::string &objectName)
Constructor.
Definition: Exception.cpp:281
const char * what() const noexcept override
Writes out the range and limits.
Definition: Exception.cpp:199
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.
Definition: Exception.cpp:181
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:35
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:44
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)