00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdexcept>
00019 #include <iostream>
00020 #include <string>
00021 #include <iomanip>
00022 #include <sstream>
00023
00024 class IOError : public std::runtime_error {
00025 protected:
00026 std::string _msg;
00027 public:
00028 IOError() : std::runtime_error(""), _msg("") {}
00029 IOError(std::string msg) : std::runtime_error(""), _msg(msg) {}
00030 virtual ~IOError() throw() {}
00031 virtual const char* what() const throw() { return _msg.c_str(); }
00032 };
00033
00034 class FileIOError : public IOError {
00035 public:
00036 FileIOError() : IOError("general file IO error") {}
00037 FileIOError(std::string fileName, std::string msg) : IOError(fileName + ": " + msg) {}
00038 FileIOError(std::string fileName, int line, std::string msg) : IOError() {
00039 std::ostringstream str;
00040 str << "file " << fileName << " at line " << line << ": " << msg;
00041 _msg = str.str();
00042 };
00043 };