PLaSK library
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
/*
2
* This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3
* Copyright (c) 2022 Lodz University of Technology
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, version 3.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*/
14
#ifndef PLASK__EXCEPTIONS_H
15
#define PLASK__EXCEPTIONS_H
16
21
#include <stdexcept>
22
#include "
utils/format.hpp
"
23
#include "
utils/string.hpp
"
24
25
#include <plask/config.hpp>
26
27
namespace
plask
{
28
29
#ifdef _MSC_VER
30
#pragma warning(push)
31
#pragma warning( disable : 4275 )
// Disable MSVC warnings "non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'"
32
#endif
33
37
struct
PLASK_API
Exception
:
public
std::runtime_error {
38
40
Exception
(
const
std::string&
msg
);
41
45
template
<
typename
... T>
46
Exception
(
const
std::string&
msg
,
const
T&...
args
):
Exception
(format(
msg
,
args
...)) {}
47
};
48
49
#ifdef _MSC_VER
50
#pragma warning(pop)
51
#endif
52
56
struct
PLASK_API
CriticalException
:
public
Exception
{
57
59
CriticalException
(
const
std::string&
msg
):
Exception
(
"Critical exception: "
+
msg
) {}
60
61
template
<
typename
... T>
62
CriticalException
(
const
std::string&
msg
,
const
T&...
args
):
Exception
(
"Critical exception: "
+
msg
,
args
...) {}
63
};
64
68
struct
PLASK_API
NotImplemented
:
public
Exception
{
69
//std::string methodName;
70
72
NotImplemented
(
const
std::string&
method_name
)
73
:
Exception
(
"Method not implemented: "
+
method_name
)
/*, methodName(method_name)*/
{}
74
79
NotImplemented
(
const
std::string&
where
,
const
std::string&
method_name
)
80
:
Exception
(
where
+
": Method not implemented: "
+
method_name
)
/*, methodName(method_name)*/
{}
81
};
82
86
struct
PLASK_API
OutOfBoundsException
:
public
Exception
{
87
88
OutOfBoundsException
(
const
std::string&
where
,
const
std::string&
argname
)
89
:
Exception
(
"{0}: argument {1} out of bounds"
,
where
,
argname
) {}
90
91
template
<
typename
BoundTypeWas,
typename
BoundTypeLo,
typename
BoundTypeHi>
92
OutOfBoundsException
(
const
std::string&
where
,
const
std::string&
argname
,
const
BoundTypeWas
&
was
,
const
BoundTypeLo
& lo,
const
BoundTypeHi
& hi)
93
:
Exception
(
"{0}: argument {1} out of bounds, should be between {2} and {3}, but was {4}"
,
where
,
argname
, lo, hi,
was
) {}
94
};
95
99
struct
PLASK_API
DimensionError
:
public
Exception
{
100
template
<
typename
... T>
101
DimensionError
(T...
args
) :
Exception
(
args
...) {}
102
};
103
107
struct
PLASK_API
BadInput
:
public
Exception
{
108
114
template
<
typename
... Params>
115
BadInput
(
const
std::string&
where
,
const
std::string&
msg
, Params... params)
116
:
Exception
(
"{0}: {1}"
,
where
, format(
msg
, params...)) {};
117
};
118
122
struct
PLASK_API
DataError
:
public
Exception
{
123
128
template
<
typename
... Params>
129
DataError
(
const
std::string&
msg
, Params... params)
130
:
Exception
(
"{0}"
, format(
msg
, params...)) {};
131
};
132
133
137
struct
PLASK_API
ComputationError
:
public
Exception
{
138
144
template
<
typename
... Params>
145
ComputationError
(
const
std::string&
where
,
const
std::string&
msg
, Params... params)
146
:
Exception
(
"{0}: {1}"
,
where
, format(
msg
, params...)) {};
147
};
148
152
struct
PLASK_API
BadId
:
public
Exception
{
153
154
BadId
(
const
std::string&
where
,
const
char
*
str_to_check
)
155
:
Exception
(
"\"{0}\" is a bad name for a {1} (must be letters, digits, or '_' and cannot start with a digit) "
,
str_to_check
,
where
) {};
156
157
static
void
throwIfBad
(
const
std::string&
where
,
const
char
*
str_to_check
) {
158
if
(!
isCid
(
str_to_check
))
159
throw
BadId
(
where
,
str_to_check
);
160
}
161
162
static
void
throwIfBad
(
const
std::string&
where
,
const
std::string&
str_to_check
) {
163
throwIfBad(
where
,
str_to_check
.c_str());
164
}
165
166
};
167
168
//-------------- Connected with providers/receivers: -----------------------
169
175
struct
PLASK_API
NoProvider
:
public
Exception
{
176
NoProvider
(
const
char
*
provider_name
):
Exception
(
"No provider nor value for {0}"
,
provider_name
) {}
177
};
178
179
struct
PLASK_API
NoValue
:
public
Exception
{
180
NoValue
(
const
char
*
provider_name
):
Exception
(
"{0} cannot be provided now"
, [](
std
::string s)->
std
::string{s[0]=
char
(
std
::
toupper
(s[0]));
return
s;}(
provider_name
) ) {}
181
};
182
183
184
/*
185
* Exceptions of this class are thrownwhen some string parser find errors.
186
*/
187
/*struct ParseException: public Exception {
188
ParseException(): Exception("Parse error") {}
189
ParseException(std::string& msg): Exception("Parse error: " + msg) {}
190
};*/
191
192
//-------------- Connected with materials: -----------------------
193
197
class
PLASK_API
NoSuchMaterial
:
public
Exception
{
198
199
template
<
typename
ComponentMap>
200
std::string constructMsg(
const
ComponentMap& comp,
const
std::string dopant_name) {
201
std::string result =
"No material with composition consisting of:"
;
202
for
(
auto
c: comp) (result +=
' '
) += c.first;
203
if
(!dopant_name.empty()) (result +=
", doped with: "
) += dopant_name;
204
return
result;
205
}
206
207
public
:
209
NoSuchMaterial
(
const
std::string& material_name)
210
:
Exception
(
"No such material: {0}"
, material_name)
/*, materialName(material_name)*/
{}
211
212
NoSuchMaterial
(
const
std::string& material_name,
const
std::string& dopant_name)
213
:
Exception
(
"No such material: {0}{1}{2}"
, material_name, dopant_name.empty() ?
""
:
":"
, dopant_name)
/*, materialName(material_name)*/
{}
214
215
template
<
typename
ComponentMap>
216
NoSuchMaterial
(
const
ComponentMap& comp,
const
std::string dopant_name)
217
:
Exception
(constructMsg(comp, dopant_name)) {}
218
219
};
220
224
struct
PLASK_API
MaterialMethodNotImplemented
:
public
NotImplemented
{
225
230
MaterialMethodNotImplemented
(
const
std::string& material_name,
const
std::string& method_name)
231
:
NotImplemented
(
"Material "
+ material_name, method_name) {
232
}
233
234
};
235
239
struct
PLASK_API
MaterialParseException
:
public
Exception
{
240
MaterialParseException
():
Exception
(
"Material parse error"
) {}
242
MaterialParseException
(
const
std::string& msg):
Exception
(msg) {}
243
244
template
<
typename
... T>
245
MaterialParseException
(
const
std::string& msg,
const
T&... args):
Exception
(msg, args...) {
246
}
247
};
248
249
class
PLASK_API
MaterialCantBeMixedException
:
public
Exception
{
250
251
/*template <typename ComponentMap>
252
std::string constructMsg(const ComponentMap& comp, const std::string dopant_name) {
253
std::string result = "material with composition consisting of:";
254
for (auto c: comp) (result += ' ') += c.first;
255
if (!dopant_name.empty()) (result += ", doped with: ") += dopant_name;
256
return result;
257
}*/
258
259
public
:
260
MaterialCantBeMixedException
(
const
std::string& material1name_with_components,
const
std::string& material2name_with_components,
const
std::string& common_dopant =
""
)
261
:
Exception
(
"Material \"{0}{2}\" can not be mixed with material \"{1}{2}\""
,
262
material1name_with_components, material2name_with_components, common_dopant.empty() ?
""
:
':'
+ common_dopant)
263
{}
264
265
};
266
267
268
//-------------- Connected with geometry: -----------------------
269
273
struct
PLASK_API
NoGeometryException
:
public
Exception
{
274
NoGeometryException
(
const
std::string& where):
Exception
(
"{0}: No geometry specified"
, where) {}
275
};
276
280
struct
PLASK_API
NoChildException
:
public
Exception
{
281
NoChildException
():
Exception
(
"Incomplete geometry tree"
) {}
282
};
283
287
struct
PLASK_API
NotUniqueObjectException
:
public
Exception
{
288
NotUniqueObjectException
():
Exception
(
"Unique object instance required"
) {}
289
NotUniqueObjectException
(
const
std::string& msg):
Exception
(msg) {}
290
291
template
<
typename
... T>
292
NotUniqueObjectException
(
const
std::string& msg,
const
T&... args):
Exception
(msg, args...) {}
293
};
294
298
struct
PLASK_API
CyclicReferenceException
:
public
Exception
{
299
CyclicReferenceException
():
Exception
(
"Detected cycle in geometry tree"
) {}
300
};
301
305
struct
PLASK_API
NoSuchGeometryObjectType
:
public
Exception
{
306
//std::string materialName;
307
311
NoSuchGeometryObjectType
(
const
std::string& object_type_name)
312
:
Exception
(
"No geometry object with given type name \""
+ object_type_name +
"\""
)
/*, materialName(material_name)*/
{}
313
};
314
318
struct
PLASK_API
NamesConflictException
:
public
Exception
{
319
324
NamesConflictException
(
const
std::string& what,
const
std::string& object_name):
325
Exception
(what +
" with name \""
+ object_name +
"\" already exists"
) {}
326
};
327
331
struct
PLASK_API
NoSuchGeometryObject
:
public
Exception
{
332
//std::string materialName;
333
337
NoSuchGeometryObject
(
const
std::string& object_name)
338
:
Exception
(
"No geometry object with name \""
+ object_name +
"\""
) {}
339
340
NoSuchGeometryObject
()
341
:
Exception
(
"No geometry object found"
) {}
342
};
343
347
struct
PLASK_API
NoSuchGeometry
:
public
Exception
{
351
NoSuchGeometry
(
const
std::string& object_name)
352
:
Exception
(
"No geometry of required type with name \""
+ object_name +
"\""
) {}
353
};
354
358
struct
PLASK_API
NoSuchPath
:
public
Exception
{
362
NoSuchPath
(
const
std::string& object_name)
363
:
Exception
(
"No path with name \""
+ object_name +
"\""
) {}
364
};
365
369
struct
PLASK_API
UnexpectedGeometryObjectTypeException
:
public
Exception
{
370
UnexpectedGeometryObjectTypeException
():
Exception
(
"Geometry object has unexpected type"
) {}
371
};
372
376
struct
PLASK_API
NoSuchAxisNames
:
public
Exception
{
377
//std::string materialName;
378
380
NoSuchAxisNames
(
const
std::string& axis_names)
381
:
Exception
(
"No such axis names \"{0}\""
, axis_names) {}
382
};
383
384
385
//-------------- Connected with meshes: -----------------------
386
390
struct
PLASK_API
NoMeshException
:
public
Exception
{
391
NoMeshException
(
const
std::string& where):
Exception
(
"{0}: No mesh specified"
, where) {}
392
};
393
394
398
struct
PLASK_API
BadMesh
:
public
Exception
{
399
405
template
<
typename
... Params>
406
BadMesh
(
const
std::string& where,
const
std::string& msg, Params... params)
407
:
Exception
(
"{0}: Bad mesh: {1}"
, where, format(msg, params...)) {};
408
};
409
410
411
412
413
}
// namespace plask
414
415
#endif
//PLASK__EXCEPTIONS_H
plask
exceptions.hpp
Generated by
1.9.8