00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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