| Disk ARchive 2.7.14 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
erreurs.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 Denis Corbin
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef ERREURS_HPP
27#define ERREURS_HPP
28
29#include "../my_config.h"
30
31#include <string>
32#include <deque>
33#include "integers.hpp"
34
35 namespace libdar
36{
37
40
42 extern const char *dar_gettext(const char *);
43
45
51 class Egeneric
52 {
53 public :
55 Egeneric(const std::string &source, const std::string &message);
56
58 Egeneric(const Egeneric & ref) = default;
59
61 Egeneric(Egeneric && ref) = default;
62
64 Egeneric & operator = (const Egeneric & ref) = default;
65
67 Egeneric & operator = (Egeneric && ref) noexcept = default;
68
70 virtual ~Egeneric() = default;
71
73 void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
74 void stack(const std::string && passage, const std::string && message = "") { pile.push_back(niveau(std::move(passage), std::move(message))); };
75
77
82 const std::string & get_message() const { return pile.front().objet; };
83
85 const std::string & get_source() const { return pile.front().lieu; };
86
88
91 const std::string & find_object(const std::string & location) const;
92
94 void prepend_message(const std::string & context);
95
97 std::string dump_str() const;
98
99 protected :
100 virtual std::string exceptionID() const = 0;
101
102 private :
103 struct niveau
104 {
105 niveau(const std::string & ou, const std::string & quoi) { lieu = ou; objet = quoi; };
106 niveau(std::string && ou, std::string && quoi) { lieu = std::move(ou); objet = std::move(quoi); };
107 niveau(const niveau & ref) = default;
108 niveau(niveau && ref) noexcept = default;
109 niveau & operator = (const niveau & ref) = default;
110 niveau & operator = (niveau && ref) noexcept = default;
111 ~niveau() = default;
112
113 std::string lieu, objet;
114 };
115
116 std::deque<niveau> pile;
117
118 static const std::string empty_string;
119 };
120
121
123
126 class Ememory : public Egeneric
127 {
128 public:
129 Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
130 Ememory(const Ememory & ref) = default;
131 Ememory(Ememory && ref) = default;
132 Ememory & operator = (const Ememory & ref) = default;
133 Ememory & operator = (Ememory && ref) = default;
134 ~Ememory() = default;
135
136 protected:
137 Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
138 virtual std::string exceptionID() const override { return "MEMORY"; };
139 };
140
142
143 class Esecu_memory : public Ememory
144 {
145 public:
146 Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
147 Esecu_memory(const Esecu_memory & ref) = default;
148 Esecu_memory(Esecu_memory && ref) = default;
149 Esecu_memory & operator = (const Esecu_memory & ref) = default;
150 Esecu_memory & operator = (Esecu_memory && ref) = default;
151 ~Esecu_memory() = default;
152
153 protected:
154 virtual std::string exceptionID() const override { return "SECU_MEMORY"; };
155 };
156
157
158#define SRC_BUG Ebug(__FILE__, __LINE__)
159// #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
160
162 class Ebug : public Egeneric
163 {
164 public :
165 Ebug(const std::string & file, S_I line);
166 Ebug(const Ebug & ref) = default;
167 Ebug(Ebug && ref) = default;
168 Ebug & operator = (const Ebug & ref) = default;
169 Ebug & operator = (Ebug && ref) = default;
170 ~Ebug() = default;
171
172 using Egeneric::stack; // to avoid warning with clang
173 void stack(const std::string & passage, const std::string & file, const std::string & line);
174
175 protected :
176 virtual std::string exceptionID() const override { return "BUG"; };
177 };
178
180
183 class Einfinint : public Egeneric
184 {
185 public :
186 Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
187 Einfinint(const Einfinint & ref) = default;
188 Einfinint(Einfinint && ref) = default;
189 Einfinint & operator = (const Einfinint & ref) = default;
190 Einfinint & operator = (Einfinint && ref) = default;
191 ~Einfinint() = default;
192
193 protected :
194 virtual std::string exceptionID() const override { return "INFININT"; };
195 };
196
198
201 class Elimitint : public Egeneric
202 {
203 public :
204 Elimitint() : Egeneric("", dar_gettext("Cannot handle such a too large integer. Use a full version of libdar (compiled to rely on the \"infinint\" integer type) to solve this problem")) {};
205 Elimitint(const Elimitint & ref) = default;
206 Elimitint(Elimitint && ref) = default;
207 Elimitint & operator = (const Elimitint & ref) = default;
208 Elimitint & operator = (Elimitint && ref) = default;
209 ~Elimitint() = default;
210
211 protected :
212 virtual std::string exceptionID() const override { return "LIMITINT"; };
213 };
214
216
219 class Erange : public Egeneric
220 {
221 public :
222 Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
223 Erange(const Erange & ref) = default;
224 Erange(Erange && ref) = default;
225 Erange & operator = (const Erange & ref) = default;
226 Erange & operator = (Erange && ref) = default;
227 ~Erange() = default;
228
229 protected :
230 virtual std::string exceptionID() const override { return "RANGE"; };
231 };
232
234
238 class Edeci : public Egeneric
239 {
240 public :
241 Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
242 Edeci(const Edeci & ref) = default;
243 Edeci(Edeci && ref) = default;
244 Edeci & operator = (const Edeci & ref) = default;
245 Edeci & operator = (Edeci && ref) = default;
246 ~Edeci() = default;
247
248 protected :
249 virtual std::string exceptionID() const override { return "DECI"; };
250 };
251
253
256 class Efeature : public Egeneric
257 {
258 public :
259 Efeature(const std::string & message) : Egeneric("", message) {};
260 Efeature(const Efeature & ref) = default;
261 Efeature(Efeature && ref) = default;
262 Efeature & operator = (const Efeature & ref) = default;
263 Efeature & operator = (Efeature && ref) = default;
264 ~Efeature() = default;
265
266 protected :
267 virtual std::string exceptionID() const override { return "UNIMPLEMENTED FEATURE"; };
268 };
269
271
274 class Ehardware : public Egeneric
275 {
276 public :
277 Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
278 Ehardware(const Ehardware & ref) = default;
279 Ehardware(Ehardware && ref) = default;
280 Ehardware & operator = (const Ehardware & ref) = default;
281 Ehardware & operator = (Ehardware && ref) = default;
282 ~Ehardware() = default;
283
284 protected :
285 virtual std::string exceptionID() const override { return "HARDWARE ERROR"; };
286 };
287
289
292 class Euser_abort : public Egeneric
293 {
294 public :
295 Euser_abort(const std::string & msg) : Egeneric("",msg) {};
296 Euser_abort(const Euser_abort & ref) = default;
297 Euser_abort(Euser_abort && ref) = default;
298 Euser_abort & operator = (const Euser_abort & ref) = default;
299 Euser_abort & operator = (Euser_abort && ref) = default;
300 ~Euser_abort() = default;
301
302 protected :
303 virtual std::string exceptionID() const override { return "USER ABORTED OPERATION"; };
304 };
305
306
308
311 class Edata : public Egeneric
312 {
313 public :
314 Edata(const std::string & msg) : Egeneric("", msg) {};
315 Edata(const Edata & ref) = default;
316 Edata(Edata && ref) = default;
317 Edata & operator = (const Edata & ref) = default;
318 Edata & operator = (Edata && ref) = default;
319 ~Edata() = default;
320
321 protected :
322 virtual std::string exceptionID() const override { return "ERROR IN TREATED DATA"; };
323 };
324
326
329 class Escript : public Egeneric
330 {
331 public :
332 Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
333 Escript(const Escript & ref) = default;
334 Escript(Escript && ref) = default;
335 Escript & operator = (const Escript & ref) = default;
336 Escript & operator = (Escript && ref) = default;
337 ~Escript() = default;
338
339 protected :
340 virtual std::string exceptionID() const override { return "USER ABORTED OPERATION"; };
341 };
342
344
347 class Elibcall : public Egeneric
348 {
349 public :
350 Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
351 Elibcall(const Elibcall & ref) = default;
352 Elibcall(Elibcall && ref) = default;
353 Elibcall & operator = (const Elibcall & ref) = default;
354 Elibcall & operator = (Elibcall && ref) = default;
355 ~Elibcall() = default;
356
357 protected :
358 virtual std::string exceptionID() const override { return "USER ABORTED OPERATION"; };
359 };
360
362
365 class Ecompilation : public Egeneric
366 {
367 public :
368 Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
369 Ecompilation(const Ecompilation & ref) = default;
370 Ecompilation(Ecompilation && ref) = default;
371 Ecompilation & operator = (const Ecompilation & ref) = default;
372 Ecompilation & operator = (Ecompilation && ref) = default;
373 ~Ecompilation() = default;
374
375 protected :
376 virtual std::string exceptionID() const override { return "FEATURE DISABLED AT COMPILATION TIME"; };
377 };
378
379
381
382 class Ethread_cancel : public Egeneric
383 {
384 public:
385 Ethread_cancel(bool now, U_64 x_flag) : Egeneric("", now ? dar_gettext("Thread cancellation requested, aborting as soon as possible") : dar_gettext("Thread cancellation requested, aborting as properly as possible")) { immediate = now; flag = x_flag; };
386 Ethread_cancel(const Ethread_cancel & ref) = default;
387 Ethread_cancel(Ethread_cancel && ref) = default;
388 Ethread_cancel & operator = (const Ethread_cancel & ref) = default;
389 Ethread_cancel & operator = (Ethread_cancel && ref) = default;
390 ~Ethread_cancel() = default;
391
392 bool immediate_cancel() const { return immediate; };
393 U_64 get_flag() const { return flag; };
394
395 protected:
396 virtual std::string exceptionID() const override { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
397
398 private:
399 bool immediate;
400 U_64 flag;
401 };
402
404
405 class Esystem : public Egeneric
406 {
407 public:
408 enum io_error
409 {
410 io_exist, //< file already exists (write mode)
411 io_absent, //< file does not exist (read mode)
412 io_access, //< permission denied (any mode)
413 io_ro_fs //< read-only filesystem (write mode/read-write mode)
414 };
415
416 Esystem(const std::string & source, const std::string & message, io_error code);
417 Esystem(const Esystem & ref) = default;
418 Esystem(Esystem && ref) = default;
419 Esystem & operator = (const Esystem & ref) = default;
420 Esystem & operator = (Esystem && ref) = default;
421 ~Esystem() = default;
422
423 io_error get_code() const { return x_code; };
424
425 protected:
426 virtual std::string exceptionID() const override { return "SYSTEM ERROR MET"; };
427
428 private:
429 io_error x_code;
430 };
431
433
434 class Enet_auth : public Egeneric
435 {
436 public:
437 Enet_auth(const std::string & message): Egeneric("on the network", message) {};
438 Enet_auth(const Enet_auth & ref) = default;
439 Enet_auth(Enet_auth && ref) = default;
440 Enet_auth & operator = (const Enet_auth & ref) = default;
441 Enet_auth & operator = (Enet_auth && ref) = default;
442 ~Enet_auth() = default;
443
444 protected:
445 virtual std::string exceptionID() const override { return "NETWORK AUTHENTICATION ERROR"; };
446 };
447
448
450
451} // end of namespace
452
453#endif
libdar::Ebug
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition erreurs.hpp:163
libdar::Ecompilation
exception used when a requested fearture has not beed activated at compilation time
Definition erreurs.hpp:366
libdar::Edata
exception used when an error concerning the treated data has been met
Definition erreurs.hpp:312
libdar::Edeci
exception used to signal convertion problem between infinint and string (decimal representation)
Definition erreurs.hpp:239
libdar::Efeature
exception used when a requested feature is not (yet) implemented
Definition erreurs.hpp:257
libdar::Egeneric
this is the parent class of all exception classes.
Definition erreurs.hpp:52
libdar::Egeneric::stack
void stack(const std::string &passage, const std::string &message="")
add more detailed couple of information to the exception
Definition erreurs.hpp:73
libdar::Egeneric::Egeneric
Egeneric(const std::string &source, const std::string &message)
the constructor
libdar::Egeneric::Egeneric
Egeneric(Egeneric &&ref)=default
move constructor
libdar::Egeneric::~Egeneric
virtual ~Egeneric()=default
the destructor
libdar::Egeneric::get_source
const std::string & get_source() const
get the call function which has thrown this exception
Definition erreurs.hpp:85
libdar::Egeneric::prepend_message
void prepend_message(const std::string &context)
prepend error message by the given string
libdar::Egeneric::dump_str
std::string dump_str() const
return a string result of the exception information dump
libdar::Egeneric::Egeneric
Egeneric(const Egeneric &ref)=default
copy constructor
libdar::Egeneric::get_message
const std::string & get_message() const
get the message explaing the nature of the exception
Definition erreurs.hpp:82
libdar::Egeneric::find_object
const std::string & find_object(const std::string &location) const
retrieve the objet (object) associated to a given "lieu" (location) from the stack
libdar::Egeneric::operator=
Egeneric & operator=(const Egeneric &ref)=default
assignment operator
libdar::Ehardware
exception used when hardware problem is found
Definition erreurs.hpp:275
libdar::Einfinint
exception used when arithmetic error is detected when operating on infinint
Definition erreurs.hpp:184
libdar::Elibcall
exception used to signal an error in the argument given to libdar call of the API
Definition erreurs.hpp:348
libdar::Elimitint
exception used when a limitint overflow is detected, the maximum value of the limitint has been excee...
Definition erreurs.hpp:202
libdar::Ememory
exception used when memory has been exhausted
Definition erreurs.hpp:127
libdar::Enet_auth
exception used to report authentication error
Definition erreurs.hpp:435
libdar::Erange
exception used to signal range error
Definition erreurs.hpp:220
libdar::Escript
exception used when error the inter-slice user command returned an error code
Definition erreurs.hpp:330
libdar::Esecu_memory
exception used when secure memory has been exhausted
Definition erreurs.hpp:144
libdar::Esystem
exception used to carry system error
Definition erreurs.hpp:406
libdar::Ethread_cancel
exception used when the thread libdar is running in is asked to stop
Definition erreurs.hpp:383
libdar::Euser_abort
exception used to signal that the user has aborted the operation
Definition erreurs.hpp:293
libdar::pile
stores a stack of generic_files writing/reading on each others
Definition pile.hpp:44
libdar::dar_gettext
const char * dar_gettext(const char *)
a routine to change NLS domaine forth and back for inline routines
integers.hpp
are defined here basic integer types that tend to be portable
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47