Disk ARchive  2.4.2
 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 2011/05/20 10:23:07 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 
40 #define E_BEGIN try {
41 #define E_END(passage, message) } catch(Egeneric & e) { e.stack(passage, message); throw; }
42 
45 
47  extern const char *dar_gettext(const char *);
48 
50 
56  class Egeneric
57  {
58  public :
60  Egeneric(const std::string &source, const std::string &message);
62  Egeneric(const Egeneric & ref) { pile = ref.pile; };
64  virtual ~Egeneric() {};
65 
67  virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
68 
70 
75  const std::string & get_message() const { return pile.front().objet; };
76 
78  const std::string & get_source() const { return pile.front().lieu; };
79 
81 
84  const std::string & find_object(const std::string & location) const;
85 
87  void prepend_message(const std::string & context);
88 
90  void dump() const;
91 
92  protected :
93  virtual std::string exceptionID() const = 0;
94 
95  private :
96  struct niveau
97  {
98  niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
99  std::string lieu, objet;
100  };
101 
102  std::list<niveau> pile;
103 
104  static const std::string empty_string;
105  };
106 
107 
109 
112  class Ememory : public Egeneric
113  {
114  public:
115  Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
116 
117  protected:
118  Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
119  std::string exceptionID() const { return "MEMORY"; };
120  };
121 
123 
124  class Esecu_memory : public Ememory
125  {
126  public:
127  Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
128 
129  protected:
130  std::string exceptionID() const { return "SECU_MEMORY"; };
131  };
132 
133 
134 #define SRC_BUG Ebug(__FILE__, __LINE__)
135 #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
136 
138  class Ebug : public Egeneric
139  {
140  public :
141  Ebug(const std::string & file, S_I line);
142 
143  void stack(const std::string & passage, const std::string & file, const std::string & line);
144 
145  protected :
146  std::string exceptionID() const { return "BUG"; };
147  };
148 
150 
153  class Einfinint : public Egeneric
154  {
155  public :
156  Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
157 
158  protected :
159  std::string exceptionID() const { return "INFININT"; };
160  };
161 
163 
166  class Elimitint : public Egeneric
167  {
168  public :
169  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")) {};
170 
171  protected :
172  std::string exceptionID() const { return "LIMITINT"; };
173  };
174 
176 
179  class Erange : public Egeneric
180  {
181  public :
182  Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
183 
184  protected :
185  std::string exceptionID() const { return "RANGE"; };
186  };
187 
189 
193  class Edeci : public Egeneric
194  {
195  public :
196  Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
197 
198  protected :
199  std::string exceptionID() const { return "DECI"; };
200  };
201 
203 
206  class Efeature : public Egeneric
207  {
208  public :
209  Efeature(const std::string & message) : Egeneric("", message) {};
210 
211  protected :
212  std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
213  };
214 
216 
219  class Ehardware : public Egeneric
220  {
221  public :
222  Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
223 
224  protected :
225  std::string exceptionID() const { return "HARDWARE ERROR"; };
226  };
227 
229 
232  class Euser_abort : public Egeneric
233  {
234  public :
235  Euser_abort(const std::string & msg) : Egeneric("",msg) {};
236 
237  protected :
238  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
239  };
240 
241 
243 
246  class Edata : public Egeneric
247  {
248  public :
249  Edata(const std::string & msg) : Egeneric("", msg) {};
250 
251  protected :
252  std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
253  };
254 
256 
259  class Escript : public Egeneric
260  {
261  public :
262  Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
263 
264  protected :
265  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
266  };
267 
269 
272  class Elibcall : public Egeneric
273  {
274  public :
275  Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
276 
277  protected :
278  std::string exceptionID() const { return "USER ABORTED OPERATION"; };
279  };
280 
282 
285  class Ecompilation : public Egeneric
286  {
287  public :
288  Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
289 
290  protected :
291  std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
292  };
293 
294 
296 
297  class Ethread_cancel : public Egeneric
298  {
299  public:
300  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; };
301 
302  bool immediate_cancel() const { return immediate; };
303  U_64 get_flag() const { return flag; };
304 
305  protected:
306  std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
307 
308  private:
309  bool immediate;
310  U_64 flag;
311  };
312 
313 
315 
316 } // end of namespace
317 
318 #endif