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.2.1 2007/07/27 16:02:49 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         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 } // end of namespace
00299 
00300 #endif

Generated on Sat Mar 1 02:35:36 2008 for Disk ARchive by  doxygen 1.5.3