Disk ARchive  2.4.15
 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  using Egeneric::stack; // to avoid warning with clang
137  void stack(const std::string & passage, const std::string & file, const std::string & line);
138 
139  protected :
140  std::string exceptionID() const { return "BUG"; };
141  };
142 
144 
147  class Einfinint : public Egeneric
148  {
149  public :
150  Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
151 
152  protected :
153  std::string exceptionID() const { return "INFININT"; };
154  };
155 
157 
160  class Elimitint : public Egeneric
161  {
162  public :
163  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")) {};
164 
165  protected :
166  std::string exceptionID() const { return "LIMITINT"; };
167  };
168 
170 
173  class Erange : public Egeneric
174  {
175  public :
176  Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
177 
178  protected :
179  std::string exceptionID() const { return "RANGE"; };
180  };
181 
183 
187  class Edeci : public Egeneric
188  {
189  public :
190  Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
191 
192  protected :
193  std::string exceptionID() const { return "DECI"; };
194  };
195 
197 
200  class Efeature : public Egeneric
201  {
202  public :
203  Efeature(const std::string & message) : Egeneric("", message) {};
204 
205  protected :
206  std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
207  };
208 
210 
213  class Ehardware : public Egeneric
214  {
215  public :
216  Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
217 
218  protected :
219  std::string exceptionID() const { return "HARDWARE ERROR"; };
220  };
221 
223 
226  class Euser_abort : public Egeneric
227  {
228  public :
229  Euser_abort(const std::string & msg) : Egeneric("",msg) {};
230 
231  protected :
232  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
233  };
234 
235 
237 
240  class Edata : public Egeneric
241  {
242  public :
243  Edata(const std::string & msg) : Egeneric("", msg) {};
244 
245  protected :
246  std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
247  };
248 
250 
253  class Escript : public Egeneric
254  {
255  public :
256  Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
257 
258  protected :
259  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
260  };
261 
263 
266  class Elibcall : public Egeneric
267  {
268  public :
269  Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
270 
271  protected :
272  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
273  };
274 
276 
279  class Ecompilation : public Egeneric
280  {
281  public :
282  Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
283 
284  protected :
285  std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
286  };
287 
288 
290 
291  class Ethread_cancel : public Egeneric
292  {
293  public:
294  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; };
295 
296  bool immediate_cancel() const { return immediate; };
297  U_64 get_flag() const { return flag; };
298 
299  protected:
300  std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
301 
302  private:
303  bool immediate;
304  U_64 flag;
305  };
306 
307 
309 
310 } // end of namespace
311 
312 #endif