Newer
Older
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
#include "Exception.h"
#include <typeinfo>
namespace Mantid
{
namespace Kernel
{
/** No Arg Constructor
Intialises the nested exception to 0
*/
Exception::Exception(): _pNested(0)
{
}
/** Constructor
@param msg Sets the message that the Exception will carry
*/
Exception::Exception(const std::string& msg): _msg(msg), _pNested(0)
{
}
/** Constructor
@param msg Sets the message that the Exception will carry
@param arg message arguments are appeneded to the end of the message with a preceding ': '
*/
Exception::Exception(const std::string& msg, const std::string& arg): _msg(msg), _pNested(0)
{
if (!arg.empty())
{
_msg.append(": ");
_msg.append(arg);
}
}
/** Constructor
@param msg Sets the message that the Exception will carry
@param nested A nested exception which is cloned and held within this exception
*/
Exception::Exception(const std::string& msg, const Exception& nested): _msg(msg), _pNested(nested.clone())
{
}
/** Constructor
@param nested A nested exception, the message for this exception is taken from the inner exception
*/
Exception::Exception(const Exception& exc): std::exception(exc)
{
_msg = exc._msg;
_pNested = exc._pNested ? exc._pNested->clone() : 0;
}
/// Destructor
Exception::~Exception() throw()
{
delete _pNested;
}
/** Copy contructor
@param exc The excption to copy
@returns The copied exception
*/
Exception& Exception::operator = (const Exception& exc)
{
if (&exc != this)
{
delete _pNested;
_msg = exc._msg;
_pNested = exc._pNested ? exc._pNested->clone() : 0;
}
return *this;
}
/** Gets the name of the exception
@returns the name of the exception
*/
const char* Exception::name() const throw()
{
return "Exception";
}
/** Gets the classname of the exception
@returns the classname of the exception
*/
const char* Exception::className() const throw()
{
return typeid(*this).name();
}
/** Gets the name of the exception (compatible with std::exception)
@returns the name of the exception
*/
const char* Exception::what() const throw()
{
return name();
}
/** Gets the name and message of the exception formatted for display or logging
@returns the name and message of the exception
*/
std::string Exception::displayText() const
{
std::string txt = name();
if (!_msg.empty())
{
txt.append(": ");
txt.append(_msg);
}
return txt;
}
/** Creates an exact copy of the exception.
The copy can later be thrown again by
invoking rethrow() on it.
@returns A pointer to the cloned exception
*/
Exception* Exception::clone() const
{
return new Exception(*this);
}
/** (Re)Throws the exception.
This is useful for temporarily storing a
copy of an exception (see clone()), then
throwing it again.
*/
void Exception::rethrow() const
{
throw *this;
}
/** Gets the nested exception
@returns A pointer to the nested exception
*/
const Exception* Exception::nested() const
{
return _pNested;
}
/** gets the message of the exception
@returns A reference to the message
*/
const std::string& Exception::message() const
{
return _msg;
}
MANTID_IMPLEMENT_EXCEPTION(LogicException, Exception, "Logic exception")
MANTID_IMPLEMENT_EXCEPTION(AssertionViolationException, LogicException, "Assertion violation")
MANTID_IMPLEMENT_EXCEPTION(NullPointerException, LogicException, "Null pointer")
MANTID_IMPLEMENT_EXCEPTION(InvalidArgumentException, LogicException, "Invalid argument")
MANTID_IMPLEMENT_EXCEPTION(NotImplementedException, LogicException, "Not implemented")
MANTID_IMPLEMENT_EXCEPTION(RangeException, LogicException, "Out of range")
MANTID_IMPLEMENT_EXCEPTION(RuntimeException, Exception, "Runtime exception")
MANTID_IMPLEMENT_EXCEPTION(NotFoundException, RuntimeException, "Not found")
MANTID_IMPLEMENT_EXCEPTION(ExistsException, RuntimeException, "Exists")
MANTID_IMPLEMENT_EXCEPTION(TimeoutException, RuntimeException, "Timeout")
MANTID_IMPLEMENT_EXCEPTION(SystemException, RuntimeException, "System exception")
MANTID_IMPLEMENT_EXCEPTION(LibraryLoadException, RuntimeException, "Cannot load library")
MANTID_IMPLEMENT_EXCEPTION(LibraryAlreadyLoadedException, RuntimeException, "Library already loaded")
MANTID_IMPLEMENT_EXCEPTION(NoPermissionException, RuntimeException, "No permission")
MANTID_IMPLEMENT_EXCEPTION(OutOfMemoryException, RuntimeException, "Out of memory")
MANTID_IMPLEMENT_EXCEPTION(DataException, RuntimeException, "Data error")
MANTID_IMPLEMENT_EXCEPTION(DataFormatException, DataException, "Bad data format")
MANTID_IMPLEMENT_EXCEPTION(SyntaxException, DataException, "Syntax error")
MANTID_IMPLEMENT_EXCEPTION(PathSyntaxException, SyntaxException, "Bad path syntax")
MANTID_IMPLEMENT_EXCEPTION(IOException, RuntimeException, "I/O error")
MANTID_IMPLEMENT_EXCEPTION(FileException, IOException, "File access error")
MANTID_IMPLEMENT_EXCEPTION(FileExistsException, FileException, "File exists")
MANTID_IMPLEMENT_EXCEPTION(FileNotFoundException, FileException, "File not found")
MANTID_IMPLEMENT_EXCEPTION(PathNotFoundException, FileException, "Path not found")
MANTID_IMPLEMENT_EXCEPTION(FileReadOnlyException, FileException, "File is read-only")
MANTID_IMPLEMENT_EXCEPTION(FileAccessDeniedException, FileException, "Access to file denied")
MANTID_IMPLEMENT_EXCEPTION(CreateFileException, FileException, "Cannot create file")
MANTID_IMPLEMENT_EXCEPTION(OpenFileException, FileException, "Cannot open file")
MANTID_IMPLEMENT_EXCEPTION(WriteFileException, FileException, "Cannot write file")
MANTID_IMPLEMENT_EXCEPTION(ReadFileException, FileException, "Cannot read file")
MANTID_IMPLEMENT_EXCEPTION(ApplicationException, Exception, "Application exception")
MANTID_IMPLEMENT_EXCEPTION(BadCastException, RuntimeException, "Bad cast exception")
} // namespace Kernel
} // namespace Mantid