erreurs.hpp

Go to the documentation of this file.
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 : dar.linux@free.fr
00020 /*********************************************************************/
00021 // $Id: erreurs.hpp,v 1.15 2005/05/30 15:52:38 edrusb Rel $
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         std::string get_message() const { return pile.front().objet; };
00073 
00075         std::string get_source() const { return pile.front().lieu; };
00076 
00078         void dump() const;
00079 
00080     protected :
00081         virtual std::string exceptionID() const = 0;
00082 
00083     private :
00084         struct niveau
00085         {
00086             niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
00087             std::string lieu, objet;
00088         };
00089 
00090         std::list<niveau> pile;
00091     };
00092 
00093 
00095 
00098     class Ememory : public Egeneric
00099     {
00100     public:
00101         Ememory(const std::string &source) : Egeneric(source, gettext("Lack of Memory")) {};
00102 
00103     protected :
00104         std::string exceptionID() const { return "MEMORY"; };
00105     };
00106 
00107 #define SRC_BUG Ebug(__FILE__, __LINE__)
00108 #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
00109 
00111     class Ebug : public Egeneric
00112     {
00113     public :
00114         Ebug(const std::string & file, S_I line);
00115 
00116         void stack(const std::string & passage, const std::string & file, const std::string & line);
00117 
00118     protected :
00119         std::string exceptionID() const { return "BUG"; };
00120     };
00121 
00123 
00126     class Einfinint : public Egeneric
00127     {
00128     public :
00129         Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00130 
00131     protected :
00132         std::string exceptionID() const { return "INFININT"; };
00133     };
00134 
00136 
00139     class Elimitint : public Egeneric
00140     {
00141     public :
00142         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")) {};
00143 
00144     protected :
00145         std::string exceptionID() const { return "LIMITINT"; };
00146     };
00147 
00149 
00152     class Erange : public Egeneric
00153     {
00154     public :
00155         Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00156 
00157     protected :
00158         std::string exceptionID() const { return "RANGE"; };
00159     };
00160 
00162 
00166     class Edeci : public Egeneric
00167     {
00168     public :
00169         Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00170 
00171     protected :
00172         std::string exceptionID() const { return "DECI"; };
00173     };
00174 
00176 
00179     class Efeature : public Egeneric
00180     {
00181     public :
00182         Efeature(const std::string & message) : Egeneric("", message) {};
00183 
00184     protected :
00185         std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
00186     };
00187 
00189 
00192     class Ehardware : public Egeneric
00193     {
00194     public :
00195         Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00196 
00197     protected :
00198         std::string exceptionID() const { return "HARDWARE ERROR"; };
00199     };
00200 
00202 
00205     class Euser_abort : public Egeneric
00206     {
00207     public :
00208         Euser_abort(const std::string & msg) : Egeneric("",msg) {};
00209 
00210     protected :
00211         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00212     };
00213 
00215 
00218     class Edata : public Egeneric
00219     {
00220     public :
00221         Edata(const std::string & msg) : Egeneric("", msg) {};
00222 
00223     protected :
00224         std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
00225     };
00226 
00228 
00231     class Escript : public Egeneric
00232     {
00233     public :
00234         Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00235 
00236     protected :
00237         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00238     };
00239 
00241 
00244     class Elibcall : public Egeneric
00245     {
00246     public :
00247         Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00248 
00249     protected :
00250         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00251     };
00252 
00254 
00257     class Ecompilation : public Egeneric
00258     {
00259     public :
00260         Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
00261 
00262     protected :
00263         std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
00264     };
00265 
00266 
00268 
00269     class Ethread_cancel : public Egeneric
00270     {
00271     public:
00272         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; };
00273 
00274         bool immediate_cancel() const { return immediate; }
00275         U_64 get_flag() const { return flag; };
00276 
00277     protected:
00278         std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
00279 
00280     private:
00281         bool immediate;
00282         U_64 flag;
00283     };
00284 
00286 
00287 } // end of namespace
00288 
00289 #endif

Generated on Wed Feb 28 02:41:07 2007 for Disk ARchive by  doxygen 1.5.1