COIN-OR::LEMON - Graph Library

Changeset 1746:874e4bc21435 in lemon-0.x


Ignore:
Timestamp:
10/28/05 10:40:42 (15 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2274
Message:

If the file does not exist LemonReader? throws exception

Location:
lemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/error.h

    r1536 r1746  
    325325
    326326    virtual ~DataFormatError() throw() {}
     327  };
     328
     329  ///\e
     330  class FileOpenError : public IOError {
     331  protected:
     332    ExceptionMember<std::string> _file;
     333
     334    mutable ExceptionMember<std::string> _message_holder;
     335  public:
     336
     337    FileOpenError(const FileOpenError &foe) :
     338      IOError(foe), _file(foe._file) {}
     339
     340    ///\e
     341    explicit FileOpenError(const std::string& file)
     342      : _file(file) {}
     343
     344
     345    ///\e
     346    void file(const std::string &file) { _file.set(file); }
     347 
     348    /// \brief Returns the filename.
     349    ///
     350    /// Returns \e null if the filename was not specified.
     351    const char* file() const {
     352      if (_file.valid() && !_file.get().empty()) {
     353        return _file.get().c_str();
     354      } else {
     355        return 0;
     356      }
     357    }
     358
     359    ///\e
     360    virtual const char* what() const throw() {
     361      try {
     362        std::ostringstream ostr;
     363        ostr << exceptionName() << ": ";
     364        ostr << "Cannot open file - " << file();
     365        _message_holder.set(ostr.str());
     366      }
     367      catch (...) {}
     368      if( _message_holder.valid()) return _message_holder.get().c_str();
     369      return exceptionName();
     370    }
     371
     372    virtual const char* exceptionName() const {
     373      return "lemon::FileOpenError";
     374    }
     375
     376    virtual ~FileOpenError() throw() {}
    327377  };
    328378
  • lemon/lemon_reader.h

    r1722 r1746  
    410410      : is(0), own_is(true) {
    411411      is = new std::ifstream(filename.c_str());
     412      if (is->fail()) {
     413        throw FileOpenError(filename);
     414      }
    412415    }
    413416
Note: See TracChangeset for help on using the changeset viewer.