00001 // -*- C++ -*- 00002 /* 00003 Phrasehunter - index and query text corpora 00004 Copyright (C) 2006 Torsten Marek (shlomme@gmx.de) & 00005 Armin Schmidt (armin.sch@gmail.com) 00006 00007 This program is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License 00009 as published by the Free Software Foundation; either version 2 00010 of the License, or (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef PHEXCEPTION_H 00023 #define PHEXCEPTION_H PHEXCEPTION_H 00024 00025 #include <string> 00026 00027 namespace PhraseHunter { 00028 00029 namespace Exceptions { 00030 00031 //! Base class for Phrasehunter exceptions. 00032 class Exception 00033 { 00034 static const unsigned int ERRMSG_SIZE = 40; 00035 00036 char m_msg[ERRMSG_SIZE]; 00037 public: 00038 Exception(const std::string& msg) // make this a const char* and strncopy it? 00039 { 00040 // this might look stupid, but it avoids memory allocation inside of exceptions 00041 // exceptions live in a "third space" and thus the array is guaranteed to be 00042 // there when the exception is created. Thus, one cannot run out of memory 00043 // during exception creation (which would result in an exception, which in turn 00044 // would abort() the program 00045 // Feel free to hit me if I'm talking nonsense /t 00046 int bytesCopied = msg.copy(m_msg, ERRMSG_SIZE - 1); 00047 m_msg[bytesCopied] = '\0'; 00048 } 00049 const char* what() const { return m_msg; } 00050 00051 }; 00052 00053 class FileError: public Exception 00054 { 00055 public: 00056 FileError(const std::string& msg) : Exception(msg) {} 00057 }; 00058 00059 class DatabaseError: public Exception 00060 { 00061 public: 00062 DatabaseError(const std::string& msg): Exception(msg) {} 00063 }; 00064 00065 class UnicodeError: public Exception 00066 { 00067 public: 00068 UnicodeError(const std::string& msg): Exception(msg) {} 00069 }; 00070 00071 class CorpusError : public Exception 00072 { 00073 public: 00074 CorpusError(const std::string& msg) : Exception(msg) {} 00075 }; 00076 00077 class NoSuchCorpusError : public CorpusError 00078 { 00079 public: 00080 NoSuchCorpusError(const std::string& msg) : CorpusError(msg) {} 00081 }; 00082 00083 class NoIndexerError : public CorpusError 00084 { 00085 public: 00086 NoIndexerError(): CorpusError("Indexer not opened") {} 00087 }; 00088 00089 00090 } 00091 } 00092 00093 #endif //PHEXCEPTION_H