Disk ARchive
2.4.2
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 // $Id: erreurs.hpp,v 1.24 2011/05/20 10:23:07 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00028 00029 #ifndef ERREURS_HPP 00030 #define ERREURS_HPP 00031 00032 #include "../my_config.h" 00033 #include <string> 00034 #include <list> 00035 #include "integers.hpp" 00036 00037 namespace libdar 00038 { 00039 00040 #define E_BEGIN try { 00041 #define E_END(passage, message) } catch(Egeneric & e) { e.stack(passage, message); throw; } 00042 00045 00047 extern const char *dar_gettext(const char *); 00048 00050 00056 class Egeneric 00057 { 00058 public : 00060 Egeneric(const std::string &source, const std::string &message); 00062 Egeneric(const Egeneric & ref) { pile = ref.pile; }; 00064 virtual ~Egeneric() {}; 00065 00067 virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); }; 00068 00070 00075 const std::string & get_message() const { return pile.front().objet; }; 00076 00078 const std::string & get_source() const { return pile.front().lieu; }; 00079 00081 00084 const std::string & find_object(const std::string & location) const; 00085 00087 void prepend_message(const std::string & context); 00088 00090 void dump() const; 00091 00092 protected : 00093 virtual std::string exceptionID() const = 0; 00094 00095 private : 00096 struct niveau 00097 { 00098 niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; }; 00099 std::string lieu, objet; 00100 }; 00101 00102 std::list<niveau> pile; 00103 00104 static const std::string empty_string; 00105 }; 00106 00107 00109 00112 class Ememory : public Egeneric 00113 { 00114 public: 00115 Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {}; 00116 00117 protected: 00118 Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {}; 00119 std::string exceptionID() const { return "MEMORY"; }; 00120 }; 00121 00123 00124 class Esecu_memory : public Ememory 00125 { 00126 public: 00127 Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {}; 00128 00129 protected: 00130 std::string exceptionID() const { return "SECU_MEMORY"; }; 00131 }; 00132 00133 00134 #define SRC_BUG Ebug(__FILE__, __LINE__) 00135 #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__) 00136 00138 class Ebug : public Egeneric 00139 { 00140 public : 00141 Ebug(const std::string & file, S_I line); 00142 00143 void stack(const std::string & passage, const std::string & file, const std::string & line); 00144 00145 protected : 00146 std::string exceptionID() const { return "BUG"; }; 00147 }; 00148 00150 00153 class Einfinint : public Egeneric 00154 { 00155 public : 00156 Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {}; 00157 00158 protected : 00159 std::string exceptionID() const { return "INFININT"; }; 00160 }; 00161 00163 00166 class Elimitint : public Egeneric 00167 { 00168 public : 00169 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")) {}; 00170 00171 protected : 00172 std::string exceptionID() const { return "LIMITINT"; }; 00173 }; 00174 00176 00179 class Erange : public Egeneric 00180 { 00181 public : 00182 Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {}; 00183 00184 protected : 00185 std::string exceptionID() const { return "RANGE"; }; 00186 }; 00187 00189 00193 class Edeci : public Egeneric 00194 { 00195 public : 00196 Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {}; 00197 00198 protected : 00199 std::string exceptionID() const { return "DECI"; }; 00200 }; 00201 00203 00206 class Efeature : public Egeneric 00207 { 00208 public : 00209 Efeature(const std::string & message) : Egeneric("", message) {}; 00210 00211 protected : 00212 std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; }; 00213 }; 00214 00216 00219 class Ehardware : public Egeneric 00220 { 00221 public : 00222 Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {}; 00223 00224 protected : 00225 std::string exceptionID() const { return "HARDWARE ERROR"; }; 00226 }; 00227 00229 00232 class Euser_abort : public Egeneric 00233 { 00234 public : 00235 Euser_abort(const std::string & msg) : Egeneric("",msg) {}; 00236 00237 protected : 00238 std::string exceptionID() const { return "USER ABORTED OPERATION"; }; 00239 }; 00240 00241 00243 00246 class Edata : public Egeneric 00247 { 00248 public : 00249 Edata(const std::string & msg) : Egeneric("", msg) {}; 00250 00251 protected : 00252 std::string exceptionID() const { return "ERROR IN TREATED DATA"; }; 00253 }; 00254 00256 00259 class Escript : public Egeneric 00260 { 00261 public : 00262 Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {}; 00263 00264 protected : 00265 std::string exceptionID() const { return "USER ABORTED OPERATION"; }; 00266 }; 00267 00269 00272 class Elibcall : public Egeneric 00273 { 00274 public : 00275 Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {}; 00276 00277 protected : 00278 std::string exceptionID() const { return "USER ABORTED OPERATION"; }; 00279 }; 00280 00282 00285 class Ecompilation : public Egeneric 00286 { 00287 public : 00288 Ecompilation(const std::string & msg) : Egeneric("" ,msg) {}; 00289 00290 protected : 00291 std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; }; 00292 }; 00293 00294 00296 00297 class Ethread_cancel : public Egeneric 00298 { 00299 public: 00300 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; }; 00301 00302 bool immediate_cancel() const { return immediate; }; 00303 U_64 get_flag() const { return flag; }; 00304 00305 protected: 00306 std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; }; 00307 00308 private: 00309 bool immediate; 00310 U_64 flag; 00311 }; 00312 00313 00315 00316 } // end of namespace 00317 00318 #endif