Disk ARchive  2.4.8
 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 #include <string>
31 #include <list>
32 #include "integers.hpp"
33 
34 namespace libdar
35 {
36 
39 
41  extern const char *dar_gettext(const char *);
42 
44 
50  class Egeneric
51  {
52  public :
54  Egeneric(const std::string &source, const std::string &message);
56  virtual ~Egeneric() {};
57 
59  virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
60 
62 
67  const std::string & get_message() const { return pile.front().objet; };
68 
70  const std::string & get_source() const { return pile.front().lieu; };
71 
73 
76  const std::string & find_object(const std::string & location) const;
77 
79  void prepend_message(const std::string & context);
80 
82  void dump() const;
83 
84  protected :
85  virtual std::string exceptionID() const = 0;
86 
87  private :
88  struct niveau
89  {
90  niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
91  std::string lieu, objet;
92  };
93 
94  std::list<niveau> pile;
95 
96  static const std::string empty_string;
97  };
98 
99 
101 
104  class Ememory : public Egeneric
105  {
106  public:
107  Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
108 
109  protected:
110  Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
111  std::string exceptionID() const { return "MEMORY"; };
112  };
113 
115 
116  class Esecu_memory : public Ememory
117  {
118  public:
119  Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
120 
121  protected:
122  std::string exceptionID() const { return "SECU_MEMORY"; };
123  };
124 
125 
126 #define SRC_BUG Ebug(__FILE__, __LINE__)
127 // #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
128 
130  class Ebug : public Egeneric
131  {
132  public :
133  Ebug(const std::string & file, S_I line);
134 
135  void stack(const std::string & passage, const std::string & file, const std::string & line);
136 
137  protected :
138  std::string exceptionID() const { return "BUG"; };
139  };
140 
142 
145  class Einfinint : public Egeneric
146  {
147  public :
148  Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
149 
150  protected :
151  std::string exceptionID() const { return "INFININT"; };
152  };
153 
155 
158  class Elimitint : public Egeneric
159  {
160  public :
161  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")) {};
162 
163  protected :
164  std::string exceptionID() const { return "LIMITINT"; };
165  };
166 
168 
171  class Erange : public Egeneric
172  {
173  public :
174  Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
175 
176  protected :
177  std::string exceptionID() const { return "RANGE"; };
178  };
179 
181 
185  class Edeci : public Egeneric
186  {
187  public :
188  Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
189 
190  protected :
191  std::string exceptionID() const { return "DECI"; };
192  };
193 
195 
198  class Efeature : public Egeneric
199  {
200  public :
201  Efeature(const std::string & message) : Egeneric("", message) {};
202 
203  protected :
204  std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
205  };
206 
208 
211  class Ehardware : public Egeneric
212  {
213  public :
214  Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
215 
216  protected :
217  std::string exceptionID() const { return "HARDWARE ERROR"; };
218  };
219 
221 
224  class Euser_abort : public Egeneric
225  {
226  public :
227  Euser_abort(const std::string & msg) : Egeneric("",msg) {};
228 
229  protected :
230  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
231  };
232 
233 
235 
238  class Edata : public Egeneric
239  {
240  public :
241  Edata(const std::string & msg) : Egeneric("", msg) {};
242 
243  protected :
244  std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
245  };
246 
248 
251  class Escript : public Egeneric
252  {
253  public :
254  Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
255 
256  protected :
257  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
258  };
259 
261 
264  class Elibcall : public Egeneric
265  {
266  public :
267  Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
268 
269  protected :
270  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
271  };
272 
274 
277  class Ecompilation : public Egeneric
278  {
279  public :
280  Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
281 
282  protected :
283  std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
284  };
285 
286 
288 
289  class Ethread_cancel : public Egeneric
290  {
291  public:
292  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; };
293 
294  bool immediate_cancel() const { return immediate; };
295  U_64 get_flag() const { return flag; };
296 
297  protected:
298  std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
299 
300  private:
301  bool immediate;
302  U_64 flag;
303  };
304 
305 
307 
308 } // end of namespace
309 
310 #endif