00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027
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
00053 class Egeneric
00054 {
00055 public :
00057 Egeneric(const std::string &source, const std::string &message);
00059 Egeneric(const Egeneric & ref) { pile = ref.pile; };
00061 virtual ~Egeneric() {};
00062
00064 virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
00065
00067
00072 const std::string & get_message() const { return pile.front().objet; };
00073
00075 const std::string & get_source() const { return pile.front().lieu; };
00076
00078
00081 const std::string & find_object(const std::string & location) const;
00082
00084 void prepend_message(const std::string & context);
00085
00087 void dump() const;
00088
00089 protected :
00090 virtual std::string exceptionID() const = 0;
00091
00092 private :
00093 struct niveau
00094 {
00095 niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
00096 std::string lieu, objet;
00097 };
00098
00099 std::list<niveau> pile;
00100
00101 static const std::string empty_string;
00102 };
00103
00104
00106
00109 class Ememory : public Egeneric
00110 {
00111 public:
00112 Ememory(const std::string &source) : Egeneric(source, gettext("Lack of Memory")) {};
00113
00114 protected :
00115 std::string exceptionID() const { return "MEMORY"; };
00116 };
00117
00118 #define SRC_BUG Ebug(__FILE__, __LINE__)
00119 #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
00120
00122 class Ebug : public Egeneric
00123 {
00124 public :
00125 Ebug(const std::string & file, S_I line);
00126
00127 void stack(const std::string & passage, const std::string & file, const std::string & line);
00128
00129 protected :
00130 std::string exceptionID() const { return "BUG"; };
00131 };
00132
00134
00137 class Einfinint : public Egeneric
00138 {
00139 public :
00140 Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00141
00142 protected :
00143 std::string exceptionID() const { return "INFININT"; };
00144 };
00145
00147
00150 class Elimitint : public Egeneric
00151 {
00152 public :
00153 Elimitint() : Egeneric("", gettext("cannot handle a too large integer. Use full version of dar_suite programs (compilation option set for using infinint) to solve this problem")) {};
00154
00155 protected :
00156 std::string exceptionID() const { return "LIMITINT"; };
00157 };
00158
00160
00163 class Erange : public Egeneric
00164 {
00165 public :
00166 Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00167
00168 protected :
00169 std::string exceptionID() const { return "RANGE"; };
00170 };
00171
00173
00177 class Edeci : public Egeneric
00178 {
00179 public :
00180 Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00181
00182 protected :
00183 std::string exceptionID() const { return "DECI"; };
00184 };
00185
00187
00190 class Efeature : public Egeneric
00191 {
00192 public :
00193 Efeature(const std::string & message) : Egeneric("", message) {};
00194
00195 protected :
00196 std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
00197 };
00198
00200
00203 class Ehardware : public Egeneric
00204 {
00205 public :
00206 Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00207
00208 protected :
00209 std::string exceptionID() const { return "HARDWARE ERROR"; };
00210 };
00211
00213
00216 class Euser_abort : public Egeneric
00217 {
00218 public :
00219 Euser_abort(const std::string & msg) : Egeneric("",msg) {};
00220
00221 protected :
00222 std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00223 };
00224
00226
00229 class Edata : public Egeneric
00230 {
00231 public :
00232 Edata(const std::string & msg) : Egeneric("", msg) {};
00233
00234 protected :
00235 std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
00236 };
00237
00239
00242 class Escript : public Egeneric
00243 {
00244 public :
00245 Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00246
00247 protected :
00248 std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00249 };
00250
00252
00255 class Elibcall : public Egeneric
00256 {
00257 public :
00258 Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00259
00260 protected :
00261 std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00262 };
00263
00265
00268 class Ecompilation : public Egeneric
00269 {
00270 public :
00271 Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
00272
00273 protected :
00274 std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
00275 };
00276
00277
00279
00280 class Ethread_cancel : public Egeneric
00281 {
00282 public:
00283 Ethread_cancel(bool now, U_64 x_flag) : Egeneric("", now ? gettext("Thread cancellation requested, aborting as soon as possible") : gettext("Thread cancellation requested, aborting as properly as possible")) { immediate = now; flag = x_flag; };
00284
00285 bool immediate_cancel() const { return immediate; }
00286 U_64 get_flag() const { return flag; };
00287
00288 protected:
00289 std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
00290
00291 private:
00292 bool immediate;
00293 U_64 flag;
00294 };
00295
00297
00298 }
00299
00300 #endif