Disk ARchive  2.4.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
erreurs.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef ERREURS_HPP
27 #define ERREURS_HPP
28 
29 #include "../my_config.h"
30 
31 #include <string>
32 #include <list>
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);
57  virtual ~Egeneric() {};
58 
60  virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
61 
63 
68  const std::string & get_message() const { return pile.front().objet; };
69 
71  const std::string & get_source() const { return pile.front().lieu; };
72 
74 
77  const std::string & find_object(const std::string & location) const;
78 
80  void prepend_message(const std::string & context);
81 
83  void dump() const;
84 
85  protected :
86  virtual std::string exceptionID() const = 0;
87 
88  private :
89  struct niveau
90  {
91  niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
92  std::string lieu, objet;
93  };
94 
95  std::list<niveau> pile;
96 
97  static const std::string empty_string;
98  };
99 
100 
102 
105  class Ememory : public Egeneric
106  {
107  public:
108  Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
109 
110  protected:
111  Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
112  std::string exceptionID() const { return "MEMORY"; };
113  };
114 
116 
117  class Esecu_memory : public Ememory
118  {
119  public:
120  Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
121 
122  protected:
123  std::string exceptionID() const { return "SECU_MEMORY"; };
124  };
125 
126 
127 #define SRC_BUG Ebug(__FILE__, __LINE__)
128 // #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
129 
131  class Ebug : public Egeneric
132  {
133  public :
134  Ebug(const std::string & file, S_I line);
135 
136  void stack(const std::string & passage, const std::string & file, const std::string & line);
137 
138  protected :
139  std::string exceptionID() const { return "BUG"; };
140  };
141 
143 
146  class Einfinint : public Egeneric
147  {
148  public :
149  Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
150 
151  protected :
152  std::string exceptionID() const { return "INFININT"; };
153  };
154 
156 
159  class Elimitint : public Egeneric
160  {
161  public :
162  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")) {};
163 
164  protected :
165  std::string exceptionID() const { return "LIMITINT"; };
166  };
167 
169 
172  class Erange : public Egeneric
173  {
174  public :
175  Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
176 
177  protected :
178  std::string exceptionID() const { return "RANGE"; };
179  };
180 
182 
186  class Edeci : public Egeneric
187  {
188  public :
189  Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
190 
191  protected :
192  std::string exceptionID() const { return "DECI"; };
193  };
194 
196 
199  class Efeature : public Egeneric
200  {
201  public :
202  Efeature(const std::string & message) : Egeneric("", message) {};
203 
204  protected :
205  std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
206  };
207 
209 
212  class Ehardware : public Egeneric
213  {
214  public :
215  Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
216 
217  protected :
218  std::string exceptionID() const { return "HARDWARE ERROR"; };
219  };
220 
222 
225  class Euser_abort : public Egeneric
226  {
227  public :
228  Euser_abort(const std::string & msg) : Egeneric("",msg) {};
229 
230  protected :
231  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
232  };
233 
234 
236 
239  class Edata : public Egeneric
240  {
241  public :
242  Edata(const std::string & msg) : Egeneric("", msg) {};
243 
244  protected :
245  std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
246  };
247 
249 
252  class Escript : public Egeneric
253  {
254  public :
255  Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
256 
257  protected :
258  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
259  };
260 
262 
265  class Elibcall : public Egeneric
266  {
267  public :
268  Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
269 
270  protected :
271  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
272  };
273 
275 
278  class Ecompilation : public Egeneric
279  {
280  public :
281  Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
282 
283  protected :
284  std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
285  };
286 
287 
289 
290  class Ethread_cancel : public Egeneric
291  {
292  public:
293  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; };
294 
295  bool immediate_cancel() const { return immediate; };
296  U_64 get_flag() const { return flag; };
297 
298  protected:
299  std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
300 
301  private:
302  bool immediate;
303  U_64 flag;
304  };
305 
306 
308 
309 } // end of namespace
310 
311 #endif
exception used to signal an error in the argument given to libdar call of the API ...
Definition: erreurs.hpp:265
virtual ~Egeneric()
the destructor
Definition: erreurs.hpp:57
are defined here basic integer types that tend to be portable
const std::string & find_object(const std::string &location) const
retrieve the objet (object) associated to a given &quot;lieu&quot; (location) from the stack ...
void dump() const
dump all information of the exception to the standard error
Egeneric(const std::string &source, const std::string &message)
the constructor
const char * dar_gettext(const char *)
a routine to change NLS domaine forth and back for inline routines
exception used when hardware problem is found
Definition: erreurs.hpp:212
exception used when a requested fearture has not beed activated at compilation time ...
Definition: erreurs.hpp:278
this is the parent class of all exception classes.
Definition: erreurs.hpp:51
exception used when a limitint overflow is detected, the maximum value of the limitint has been excee...
Definition: erreurs.hpp:159
virtual void stack(const std::string &passage, const std::string &message="")
add more detailed couple of information to the exception
Definition: erreurs.hpp:60
the plain file class
Definition: catalogue.hpp:479
exception used when an error concerning the treated data has been met
Definition: erreurs.hpp:239
exception used when secure memory has been exhausted
Definition: erreurs.hpp:117
exception used when the thread libdar is running in is asked to stop
Definition: erreurs.hpp:290
exception used when memory has been exhausted
Definition: erreurs.hpp:105
exception used when a requested feature is not (yet) implemented
Definition: erreurs.hpp:199
exception used when arithmetic error is detected when operating on infinint
Definition: erreurs.hpp:146
exception used to signal convertion problem between infinint and string (decimal representation) ...
Definition: erreurs.hpp:186
const std::string & get_message() const
get the message explaing the nature of the exception
Definition: erreurs.hpp:68
exception used to signal range error
Definition: erreurs.hpp:172
const std::string & get_source() const
get the call function which has thrown this exception
Definition: erreurs.hpp:71
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:131
void prepend_message(const std::string &context)
prepend error message by the given string
exception used to signal that the user has aborted the operation
Definition: erreurs.hpp:225
exception used when error the inter-slice user command returned an error code
Definition: erreurs.hpp:252