• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/home/pascal/depot/filedata/src/file_exceptions.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Nicolas PASCAL                                  *
00003  *   nicolas.pascal@icare.univ-lille1.fr                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (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                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef FILE_EXCEPTIONS_H
00022 #define FILE_EXCEPTIONS_H
00023 
00024 #include <string>
00025 #include <exception>
00026 #include <iostream>
00027 #include "tools.h"
00028 using namespace std;
00029 
00030 
00034 class open_file_error : public exception {
00035 public:
00042     open_file_error(const string &src_file, const int src_line, const string &file): src_file(src_file),src_line(src_line),file(file){};
00043     ~open_file_error() throw() {}
00044     ;
00049     virtual const char* what() const throw() {
00050         string m=src_file+"("+MyTools::to_string(src_line)+") : can not open the file "+file;
00051         return m.c_str();
00052     };
00053 private:
00054     string src_file;
00055     int src_line;
00056     string file;
00057 };
00058 
00062 class bad_temp_file : public exception {
00063 public:
00070     bad_temp_file(const string &src_file, const int src_line, const string &filename_pattern): src_file(src_file),src_line(src_line),filename_pattern(filename_pattern){};
00071     ~bad_temp_file() throw() {};
00076     virtual const char* what() const throw() {
00077         string m=src_file+"("+MyTools::to_string(src_line)+") : Temporary File Creation Error with mkstemp using the pattern "+filename_pattern;
00078         return m.c_str();
00079     };
00080 private:
00081     string src_file;
00082     int src_line;
00083     string filename_pattern;
00084 };
00085 
00089 class file_not_opened : public exception {
00090 public:
00091     file_not_opened(const string &filename):filename(filename) {};
00092     ~file_not_opened() throw() {};
00097     virtual const char* what() const throw() {
00098         string msg="file_not_opened : the file "+filename+" is not opened. Can't write to it";
00099         return msg.c_str();
00100     };
00101 private:
00102     string filename;
00103 };
00107 class bad_file : public exception {
00108 public:
00109     bad_file(const string & _s) {
00110         s = _s;
00111     };
00112     ~bad_file() throw() {};
00117     virtual const char* what() const throw() {
00118         string m;
00119         if (&s != NULL)
00120             m="The file "+s+" doesn't exist";
00121         else
00122             m="Empty file name";
00123         return m.c_str();
00124     };
00125 private:
00126     string s;
00127     string mode;
00128 };
00129 
00134 class bad_file_opening_mode : public exception {
00135 public:
00136     bad_file_opening_mode(const string & _file, const string & _mode= string("r")) {
00137         file = _file;
00138         mode = _mode;
00139     };
00140     ~bad_file_opening_mode() throw() {};
00145     virtual const char* what() const throw() {
00146         string m="The file "+file+" can't be opened in mode "+mode+". Check the file's access rights";
00147         return m.c_str();
00148     };
00149 private:
00150     string file;
00151     string mode;
00152 };
00153 
00157 class file_creation_error : public exception {
00158 public:
00159     file_creation_error(const std::string & _filename) {
00160         filename = _filename;
00161     };
00162     ~file_creation_error() throw() {};
00167     virtual const char* what() const throw() {
00168         string m="file_creation_error : the file "+filename+" can't be created";
00169         return m.c_str();
00170     };
00171 private:
00172     std::string filename;
00173 };
00177 class bad_open_file : public exception {
00178 public:
00179     bad_open_file(const string filename, string mode) : filename(filename),mode(mode) {};
00180     ~bad_open_file() throw() {};
00185     virtual const char* what() const throw() {
00186         string m="bad_open_file : can't open the file "+filename+" using the mode "+mode;
00187         return m.c_str();
00188     };
00189 private:
00190     string filename;
00191     string mode;
00192 };
00193 class empty_parasol_file : public exception {
00194 public:
00195     empty_parasol_file(const string filename) : filename(filename) {};
00196     ~empty_parasol_file() throw() {};
00201     virtual const char* what() const throw(){
00202         string m="The file :"+filename+" has no valid pixels.";
00203         return m.c_str();
00204     };
00205 private:
00206     string filename;
00207 };
00208 #endif
00209 
00210 

Generated on Thu Feb 14 2013 17:59:03 for filedata.kdevelop by  doxygen 1.7.1