Main Page | User's Guide | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

Errors.hxx

00001 // Copyright (C) 2003-2005 Vivien Mallet
00002 //
00003 // This file is part of SeldonData library.
00004 // SeldonData library is a tool for data processing.
00005 // 
00006 // SeldonData is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // SeldonData is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License (file "license") for more details.
00015 //
00016 // For more information, please see the SeldonData home page:
00017 //      http://spacetown.free.fr/lib/seldondata/
00018 
00019 #ifndef FILE_SELDONDATA_ERRORS_HXX
00020 
00021 #include <iostream>
00022 using std::cout;
00023 using std::endl;
00024 #include <string>
00025 
00026 namespace SeldonData
00027 {
00028   
00030   // ERROR //
00032 
00034   class Error
00035   {
00036 
00037   protected:
00039     string function;
00041     string comment;
00042 
00043   public:
00045     Error()
00046     {
00047       cout << "ERROR!" << endl;
00048       function = "";
00049       comment = "";
00050     }
00052 
00055     Error(string f)
00056     {
00057       cout << "ERROR!" << endl;
00058       function = f;
00059       comment = "";
00060     }
00062 
00066     Error(string f, string c)
00067     {
00068       cout << "ERROR!" << endl;
00069       function = f;
00070       comment = c;
00071     }
00072 
00074     virtual ~Error()
00075     {
00076     }
00077 
00079     virtual void What()
00080     {
00081       cout << "An unknown error occured";
00082       if (function.length()!=0)
00083         cout << " in " << function;
00084       cout << "." << endl;
00085       if (comment.length()!=0)
00086         cout << "   " << comment << endl;
00087       cout << endl;
00088     }
00089   };
00090 
00091 
00092 
00094   // NOMEMORY //
00096 
00097 
00099   class NoMemory: public Error
00100   {
00101 
00102   public:
00104     NoMemory(string f, string c): Error(f, c)
00105     {
00106     }
00108     NoMemory(string f): Error(f)
00109     {
00110     }
00111 
00113     virtual void What()
00114     {
00115       cout << "No more memory is available";
00116       if (this->function!="")
00117         cout << " in " << this->function;
00118       cout << "." << endl;
00119       if (this->comment!="")
00120         cout << "   " << this->comment << endl;
00121       cout << endl;
00122     }
00123 
00124   };
00125   
00126 
00127 
00129   // WRONGDIM //
00131 
00132 
00134 
00137   class WrongDim: public Error
00138   {
00139 
00140   public:
00142     WrongDim(string f, string c): Error(f, c)
00143     {
00144     }
00145 
00147     virtual void What()
00148     {
00149       cout << "Wrong dimension";
00150       if (this->function!="")
00151         cout << " in " << this->function;
00152       cout << "." << endl;
00153       if (this->comment!="")
00154         cout << "   " << this->comment << endl;
00155       cout << endl;
00156     }
00157 
00158   };
00159   
00160 
00161 
00163   // WRONGINDEX //
00165 
00166 
00168 
00171   class WrongIndex: public Error
00172   {
00173 
00174   public:
00176     WrongIndex(string f): Error(f)
00177     {
00178     }
00180     WrongIndex(string f, string c): Error(f, c)
00181     {
00182     }
00183 
00185     virtual void What()
00186     {
00187       cout << "Index out of range";
00188       if (this->function!="")
00189         cout << " in " << this->function;
00190       cout << "." << endl;
00191       if (this->comment!="")
00192         cout << "   " << this->comment << endl;
00193       cout << endl;
00194     }
00195 
00196   };
00197   
00198 
00199 
00201   // IOERROR //
00203 
00204 
00206   class IOError: public Error
00207   {
00208 
00209   public:
00211     IOError(string f, string c): Error(f, c)
00212     {
00213     }
00214 
00216     virtual void What()
00217     {
00218       cout << "An input/output operation failed";
00219       if (this->function!="")
00220         cout << " in " << this->function;
00221       cout << "." << endl;
00222       if (this->comment!="")
00223         cout << "   " << this->comment << endl;
00224       cout << endl;
00225     }
00226 
00227   };
00228 
00229 
00230 
00232   // UNDEFINED //
00234 
00235 
00237   class Undefined: public Error
00238   {
00239 
00240   public:
00242     Undefined(string f): Error(f)
00243     {
00244     }
00246     Undefined(string f, string c): Error(f, c)
00247     {
00248     }
00249 
00251     virtual void What()
00252     {
00253       if (this->function!="")
00254         cout << "Call to undefined function " << this->function;
00255       else
00256         cout << "An undefined function was called";
00257       cout << "." << endl;
00258       if (this->comment!="")
00259         cout << "   " << this->comment << endl;
00260       cout << endl;
00261     }
00262 
00263   };
00264 
00265   
00266 }  // namespace SeldonData.
00267 
00268 
00269 #define FILE_SELDONDATA_ERRORS_HXX
00270 #endif

Generated on Wed Apr 25 11:21:07 2007 for SeldonData by  doxygen 1.4.2