-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsli_exceptions.h
372 lines (310 loc) · 7.54 KB
/
sli_exceptions.h
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* sliexceptions.h
*
* This file is part of NEST
*
* Copyright (C) 2004 by
* The NEST Initiative
*
* See the file AUTHORS for details.
*
* Permission is granted to compile and modify
* this file for non-commercial use.
* See the file LICENSE for details.
*
*/
#ifndef SLIEXCEPTIONS_H
#define SLIEXCEPTIONS_H
#include "sli_name.h"
#include <iostream>
#include <string>
#include <vector>
namespace sli3
{
class SLIInterpreter;
#define UNKNOWN "unknown"
#define UNKNOWN_NUM -1
/**
* @addtogroup Exceptions Exception classes
* Exception classes that are thrown to indicate
* an error.
*/
/**
* @defgroup SLIExceptions SLI exception classes
* Exception classes that are thrown by SLI to
* indicate an error.
* @ingroup Exceptions
*/
/**
* Base class for all SLI exceptions.
* @ingroup Exceptions
* @ingroup SLIExceptions
*/
class SLIException: public std::exception
{
std::string what_;
public:
SLIException(char const * const what)
: what_(what)
{}
virtual ~SLIException() throw() {}
/**
* Returns the SLI error name, used by raiseerror.
*
* Return name of the exception as C-style string.
* Use this name to translate the exception to a SLI error.
* For example:
* @code
* catch(IllegalOperation &e)
* {
* i->error("ChangeSubnet","Target node must be a subnet or compound.");
* i->raiseerror(e.what());
* return;
* }
*@endcode
*@note The catch clause must be terminated with a return
*statement, if raiseerror was called.
*/
virtual const char * what() const throw()
{
return what_.c_str();
}
/**
* Returns a diagnostic message or empty string.
* This function is not const, because it may clear internal data fields.
*/
virtual std::string message() = 0;
};
/**
* Base class for all SLI interpreter exceptions.
* @ingroup SLIExceptions
*/
class InterpreterError: public SLIException
{
public:
virtual ~InterpreterError() throw() {}
InterpreterError(char const * const what)
: SLIException(what)
{}
};
class InvalidToken: public SLIException
{
public:
virtual ~InvalidToken() throw() {}
InvalidToken()
: SLIException("InvalidToken")
{}
std::string message();
};
class SyntaxError: public SLIException
{
public:
virtual ~SyntaxError() throw() {}
SyntaxError()
:SLIException("SyntaxError"){}
std::string message();
};
class DivisionByZero: public SLIException
{
public:
virtual ~DivisionByZero() throw() {}
DivisionByZero()
: SLIException("DivisionByZero")
{}
std::string message();
};
// -------------------- Type Mismatch -------------------------
/**
* Exception to be thrown if a given SLI type does not match the
* expected type.
* @ingroup SLIExceptions
*/
class ArgumentType: public InterpreterError
{
int where; // Number of the parameter that was wrong.
public:
ArgumentType(int w)
: InterpreterError("ArgumentType"),
where(w){}
std::string message();
};
class TypeMismatch: public InterpreterError //SLIException
{
std::string expected_;
std::string provided_;
public:
~TypeMismatch() throw() {}
TypeMismatch() :
InterpreterError("TypeMismatch")
{}
TypeMismatch(const std::string& expectedType)
: InterpreterError("TypeMismatch"),
expected_(expectedType)
{}
TypeMismatch(const std::string& expectedType, const std::string& providedType)
: InterpreterError("TypeMismatch"),
expected_(expectedType),
provided_(providedType)
{}
std::string message();
};
class SystemSignal: public InterpreterError
{
int signal_;
public:
~SystemSignal() throw() {}
SystemSignal(int s)
: InterpreterError("SystemSignal"),
signal_(s){}
std::string message();
};
// -------------------- Array Size Mismatch -------------------------
/**
* Exception to be thrown if a given SLI array has the wrong size.
* @ingroup SLIExceptions
*/
class RangeCheck: public InterpreterError
{
int size_;
public:
~RangeCheck() throw() {}
RangeCheck(int s = 0)
: InterpreterError("RangeCheck"),
size_(s)
{}
std::string message();
};
// -------------------- Dict Error -------------------------
/**
* Base Class for all SLI errors related to dictionary processing.
* @ingroup SLIExceptions
*/
class DictError: public InterpreterError
{
public:
virtual ~DictError() throw() {}
DictError(char const * const)
: InterpreterError("DictError")
{}
};
// -------------------- Unknown Name -------------------------
/**
* Exception to be thrown if an entry referenced inside a
* dictionary does not exist.
* @ingroup SLIExceptions
*/
class UndefinedName: public DictError // was UnknownName
{
std::string name_;
public:
~UndefinedName() throw() {}
UndefinedName(const std::string& name)
: DictError("UndefinedName"),
name_(name)
{}
std::string message();
};
// -------------------- Entry Type Mismatch -------------------------
/**
* Exception to be thrown if an entry referenced inside a
* dictionary has the wrong type.
* @ingroup SLIExceptions
*/
class EntryTypeMismatch: public DictError
{
std::string expected_;
std::string provided_;
public:
~EntryTypeMismatch() throw() {}
EntryTypeMismatch(const std::string& expectedType, const std::string& providedType)
: DictError("EntryTypeMismatch"),
expected_(expectedType),
provided_(providedType)
{}
std::string message();
};
// -------------------- Stack Error -------------------------
/**
* Exception to be thrown if an error occured while accessing the stack.
* @ingroup SLIExceptions
*/
class StackUnderflow: public InterpreterError
{
int needed;
int given;
public:
StackUnderflow(int n, int g)
: InterpreterError("StackUnderflow"),
needed(n),
given(g){}
std::string message();
};
// -------------------- I/O Error -------------------------
/**
* Exception to be thrown if an error occured in an I/O operation.
* @ingroup SLIExceptions
*/
class IOError: public SLIException
{
public:
~IOError() throw() {}
IOError()
: SLIException("IOError")
{}
std::string message();
};
/**
* Exception to be thrown if unaccessed dictionary items are found.
*/
class UnaccessedDictionaryEntry: public DictError
{
std::string msg_;
public:
~UnaccessedDictionaryEntry() throw() {}
//input: string with names of not accessed
UnaccessedDictionaryEntry(const std::string& m)
: DictError("UnaccessedDictionaryEntry"),
msg_(m) {}
std::string message();
};
// ------------ Module related error --------------------------
/**
* Exception to be thrown if an error occurs while
* loading/unloading dynamic modules.
* @ingroup SLIExceptions
* @todo Shouldn't this be a KernelException?
*/
class DynamicModuleManagementError: public SLIException
{
std::string msg_;
public:
~DynamicModuleManagementError() throw() {}
DynamicModuleManagementError()
: SLIException("DynamicModuleManagementError"),
msg_()
{}
DynamicModuleManagementError(std::string msg)
: SLIException("DynamicModuleManagementError"),
msg_(msg)
{}
std::string message();
};
/**
* Throw if an existing name is attempted to be redefined.
* This is relevant mainly when a newly loaded module attempts to
* redefine a model, synapse or function name.
* @ingroup SLIExceptions
*/
class NamingConflict: public SLIException
{
std::string msg_;
public:
~NamingConflict() throw() {}
NamingConflict(const std::string& m)
: SLIException("NamingConflict"),
msg_(m)
{}
std::string message();
};
}
#endif