lemon/error.h
changeset 2158 0b620ff10e7c
parent 2151 38ec4a930c05
child 2175 0975cad06c2b
equal deleted inserted replaced
9:7b8b3ed0dda4 10:a5e7d9628cba
   233       return "lemon::RangeError";
   233       return "lemon::RangeError";
   234     }
   234     }
   235   };
   235   };
   236 
   236 
   237   ///\e 
   237   ///\e 
   238   class IOError : public RuntimeError {
   238   class IoError : public RuntimeError {
   239   public:
   239   public:
   240     virtual const char* what() const throw() {
   240     virtual const char* what() const throw() {
   241       return "lemon::IOError";
   241       return "lemon::IoError";
   242     }
   242     }
   243   };
   243   };
   244 
   244 
   245   ///\e 
   245   ///\e 
   246   class DataFormatError : public IOError {
   246   class DataFormatError : public IoError {
   247   protected:
   247   protected:
   248     ExceptionMember<std::string> _message;
   248     ExceptionMember<std::string> _message;
   249     ExceptionMember<std::string> _file;
   249     ExceptionMember<std::string> _file;
   250     int _line;
   250     int _line;
   251 
   251 
   252     mutable ExceptionMember<std::string> _message_holder;
   252     mutable ExceptionMember<std::string> _message_holder;
   253   public:
   253   public:
   254 
   254 
   255     DataFormatError(const DataFormatError &dfe) : 
   255     DataFormatError(const DataFormatError &dfe) : 
   256       IOError(dfe), _message(dfe._message), _file(dfe._file),
   256       IoError(dfe), _message(dfe._message), _file(dfe._file),
   257       _line(dfe._line) {}
   257       _line(dfe._line) {}
   258 
   258 
   259     ///\e 
   259     ///\e 
   260     explicit DataFormatError(const char *the_message)
   260     explicit DataFormatError(const char *the_message)
   261       : _message(the_message), _line(0) {}
   261       : _message(the_message), _line(0) {}
   316 
   316 
   317     virtual ~DataFormatError() throw() {}
   317     virtual ~DataFormatError() throw() {}
   318   };
   318   };
   319 
   319 
   320   ///\e 
   320   ///\e 
   321   class FileOpenError : public IOError {
   321   class FileOpenError : public IoError {
   322   protected:
   322   protected:
   323     ExceptionMember<std::string> _file;
   323     ExceptionMember<std::string> _file;
   324 
   324 
   325     mutable ExceptionMember<std::string> _message_holder;
   325     mutable ExceptionMember<std::string> _message_holder;
   326   public:
   326   public:
   327 
   327 
   328     FileOpenError(const FileOpenError &foe) : 
   328     FileOpenError(const FileOpenError &foe) : 
   329       IOError(foe), _file(foe._file) {}
   329       IoError(foe), _file(foe._file) {}
   330 
   330 
   331     ///\e 
   331     ///\e 
   332     explicit FileOpenError(const std::string& file)
   332     explicit FileOpenError(const std::string& file)
   333       : _file(file) {}
   333       : _file(file) {}
   334 
   334 
   360       return "lemon::FileOpenError";
   360       return "lemon::FileOpenError";
   361     }
   361     }
   362     virtual ~FileOpenError() throw() {}
   362     virtual ~FileOpenError() throw() {}
   363   };
   363   };
   364 
   364 
   365   class IOParameterError : public IOError {
   365   class IoParameterError : public IoError {
   366   protected:
   366   protected:
   367     ExceptionMember<std::string> _message;
   367     ExceptionMember<std::string> _message;
   368     ExceptionMember<std::string> _file;
   368     ExceptionMember<std::string> _file;
   369 
   369 
   370     mutable ExceptionMember<std::string> _message_holder;
   370     mutable ExceptionMember<std::string> _message_holder;
   371   public:
   371   public:
   372 
   372 
   373     IOParameterError(const IOParameterError &ile) : 
   373     IoParameterError(const IoParameterError &ile) : 
   374       IOError(ile), _message(ile._message), _file(ile._file) {}
   374       IoError(ile), _message(ile._message), _file(ile._file) {}
   375 
   375 
   376     ///\e 
   376     ///\e 
   377     explicit IOParameterError(const char *the_message)
   377     explicit IoParameterError(const char *the_message)
   378       : _message(the_message) {}
   378       : _message(the_message) {}
   379 
   379 
   380     ///\e 
   380     ///\e 
   381     IOParameterError(const char *file_name, const char *the_message)
   381     IoParameterError(const char *file_name, const char *the_message)
   382       : _message(the_message), _file(file_name) {}
   382       : _message(the_message), _file(file_name) {}
   383 
   383 
   384      ///\e 
   384      ///\e 
   385     void message(const std::string& message) { _message.set(message); }
   385     void message(const std::string& message) { _message.set(message); }
   386     ///\e 
   386     ///\e 
   414 	if (file()) ostr << "(when reading file '" << file() << "')";
   414 	if (file()) ostr << "(when reading file '" << file() << "')";
   415 	_message_holder.set(ostr.str());
   415 	_message_holder.set(ostr.str());
   416       }
   416       }
   417       catch (...) {}
   417       catch (...) {}
   418       if( _message_holder.valid() ) return _message_holder.get().c_str();
   418       if( _message_holder.valid() ) return _message_holder.get().c_str();
   419       return "lemon:IOParameterError";
   419       return "lemon:IoParameterError";
   420     }
   420     }
   421     virtual ~IOParameterError() throw() {}
   421     virtual ~IoParameterError() throw() {}
   422   };
   422   };
   423 
   423 
   424 
   424 
   425   ///\e
   425   ///\e
   426   class AssertionFailedError : public LogicError {
   426   class AssertionFailedError : public LogicError {