Disk ARchive  2.4.5
 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 // $Id: erreurs.hpp,v 1.24.2.1 2012/02/25 14:43:44 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 #ifndef ERREURS_HPP
30 #define ERREURS_HPP
31 
32 #include "../my_config.h"
33 #include <string>
34 #include <list>
35 #include "integers.hpp"
36 
37 namespace libdar
38 {
39 
42 
44  extern const char *dar_gettext(const char *);
45 
47 
53  class Egeneric
54  {
55  public :
57  Egeneric(const std::string &source, const std::string &message);
59  virtual ~Egeneric() {};
60 
62  virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
63 
65 
70  const std::string & get_message() const { return pile.front().objet; };
71 
73  const std::string & get_source() const { return pile.front().lieu; };
74 
76 
79  const std::string & find_object(const std::string & location) const;
80 
82  void prepend_message(const std::string & context);
83 
85  void dump() const;
86 
87  protected :
88  virtual std::string exceptionID() const = 0;
89 
90  private :
91  struct niveau
92  {
93  niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
94  std::string lieu, objet;
95  };
96 
97  std::list<niveau> pile;
98 
99  static const std::string empty_string;
100  };
101 
102 
104 
107  class Ememory : public Egeneric
108  {
109  public:
110  Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
111 
112  protected:
113  Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
114  std::string exceptionID() const { return "MEMORY"; };
115  };
116 
118 
119  class Esecu_memory : public Ememory
120  {
121  public:
122  Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
123 
124  protected:
125  std::string exceptionID() const { return "SECU_MEMORY"; };
126  };
127 
128 
129 #define SRC_BUG Ebug(__FILE__, __LINE__)
130 // #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
131 
133  class Ebug : public Egeneric
134  {
135  public :
136  Ebug(const std::string & file, S_I line);
137 
138  void stack(const std::string & passage, const std::string & file, const std::string & line);
139 
140  protected :
141  std::string exceptionID() const { return "BUG"; };
142  };
143 
145 
148  class Einfinint : public Egeneric
149  {
150  public :
151  Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
152 
153  protected :
154  std::string exceptionID() const { return "INFININT"; };
155  };
156 
158 
161  class Elimitint : public Egeneric
162  {
163  public :
164  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")) {};
165 
166  protected :
167  std::string exceptionID() const { return "LIMITINT"; };
168  };
169 
171 
174  class Erange : public Egeneric
175  {
176  public :
177  Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
178 
179  protected :
180  std::string exceptionID() const { return "RANGE"; };
181  };
182 
184 
188  class Edeci : public Egeneric
189  {
190  public :
191  Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
192 
193  protected :
194  std::string exceptionID() const { return "DECI"; };
195  };
196 
198 
201  class Efeature : public Egeneric
202  {
203  public :
204  Efeature(const std::string & message) : Egeneric("", message) {};
205 
206  protected :
207  std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
208  };
209 
211 
214  class Ehardware : public Egeneric
215  {
216  public :
217  Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
218 
219  protected :
220  std::string exceptionID() const { return "HARDWARE ERROR"; };
221  };
222 
224 
227  class Euser_abort : public Egeneric
228  {
229  public :
230  Euser_abort(const std::string & msg) : Egeneric("",msg) {};
231 
232  protected :
233  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
234  };
235 
236 
238 
241  class Edata : public Egeneric
242  {
243  public :
244  Edata(const std::string & msg) : Egeneric("", msg) {};
245 
246  protected :
247  std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
248  };
249 
251 
254  class Escript : public Egeneric
255  {
256  public :
257  Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
258 
259  protected :
260  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
261  };
262 
264 
267  class Elibcall : public Egeneric
268  {
269  public :
270  Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
271 
272  protected :
273  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
274  };
275 
277 
280  class Ecompilation : public Egeneric
281  {
282  public :
283  Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
284 
285  protected :
286  std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
287  };
288 
289 
291 
292  class Ethread_cancel : public Egeneric
293  {
294  public:
295  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; };
296 
297  bool immediate_cancel() const { return immediate; };
298  U_64 get_flag() const { return flag; };
299 
300  protected:
301  std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
302 
303  private:
304  bool immediate;
305  U_64 flag;
306  };
307 
308 
310 
311 } // end of namespace
312 
313 #endif