diff --git a/modules/io/src/mol/pdb_reader.cc b/modules/io/src/mol/pdb_reader.cc index 5b047c3aa63afe64b2e8672a96980078fd155fe4..78b6bec4d63e7917647ea2d09027343e3c05e545 100644 --- a/modules/io/src/mol/pdb_reader.cc +++ b/modules/io/src/mol/pdb_reader.cc @@ -92,7 +92,9 @@ void PDBReader::Init(const boost::filesystem::path& loc) in_.push(boost::iostreams::gzip_decompressor()); } in_.push(instream_); - if(!infile_) throw IOException("could not open "+loc.string()); + if(!infile_) throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + loc.string() + "'"); line_num_=0; if(boost::iequals(boost::filesystem::extension(loc), ".pqr")) { is_pqr_=true; diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc index d4461402c725d3c9db93f1f2a1e85fc3521486e7..265a8a024d705a0e14f6d94acdad54245537fd1a 100644 --- a/modules/io/src/mol/pdb_writer.cc +++ b/modules/io/src/mol/pdb_writer.cc @@ -407,7 +407,9 @@ PDBWriter::PDBWriter(const String& filename, const IOProfile& profile): is_pqr_(false), profile_(profile), filename_(filename) { if (!outfile_.is_open()) { - throw IOException("Failed to open: " + filename); + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + filename + "'"); } if (boost::iequals(".pqr", boost::filesystem::extension(filename))) { is_pqr_=true; diff --git a/modules/io/src/mol/sdf_reader.cc b/modules/io/src/mol/sdf_reader.cc index 660a9dcb5be68494a7d5944ced083d857f945f8c..76c7091a297ab99fc422f7bc075e89e98cecb5fb 100644 --- a/modules/io/src/mol/sdf_reader.cc +++ b/modules/io/src/mol/sdf_reader.cc @@ -124,7 +124,9 @@ void SDFReader::ClearState(const boost::filesystem::path& loc) in_.push(boost::iostreams::gzip_decompressor()); } in_.push(instream_); - if(!infile_) throw IOException("could not open "+loc.string()); + if(!infile_) throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + loc.string() + "'"); curr_chain_=mol::ChainHandle(); curr_residue_=mol::ResidueHandle(); chain_count_=0; diff --git a/modules/io/src/mol/sdf_writer.cc b/modules/io/src/mol/sdf_writer.cc index c0241211ab8c2ecf0421b2487dcfb4ae19bb518e..e9fd0ded4ca1fb85a9a6fd0ea1db3c7a041d0ad4 100644 --- a/modules/io/src/mol/sdf_writer.cc +++ b/modules/io/src/mol/sdf_writer.cc @@ -171,28 +171,48 @@ namespace { } SDFWriter::SDFWriter(std::ostream& ostream) - : outfile_(), ostr_(ostream), counter_(0), atom_indices_() { + : outfile_(), ostr_(ostream), counter_(0), atom_indices_(), filename_("") { } SDFWriter::SDFWriter(const String& filename) - : outfile_(filename.c_str()), ostr_(outfile_), counter_(0), atom_indices_() { + : outfile_(filename.c_str()), ostr_(outfile_), counter_(0), atom_indices_(), + filename_(filename){ } SDFWriter::SDFWriter(const boost::filesystem::path& filename): outfile_(BFPathToString(filename).c_str()), - ostr_(outfile_), counter_(0), atom_indices_() {} + ostr_(outfile_), counter_(0), atom_indices_(), filename_("") {} void SDFWriter::Write(const mol::EntityView& ent) { if (!ostr_) { - throw IOException("Can't write SDF file. Bad output stream"); + if (!filename_.empty()) { + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + filename_ + "'"); + } + else { + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": <stream>"); + } } + mol::EntityView non_const_view = ent; non_const_view.Apply(*this); } void SDFWriter::Write(const mol::EntityHandle& ent) { if (!ostr_) { - throw IOException("Can't write SDF file. Bad output stream"); + if (!filename_.empty()) { + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + filename_ + "'"); + } + else { + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": <stream>"); + } } mol::EntityView non_const_view = ent.CreateFullView(); non_const_view.Apply(*this); diff --git a/modules/io/src/mol/sdf_writer.hh b/modules/io/src/mol/sdf_writer.hh index 8ca166d97b50c7d635ed285ccf11b0840ff97a71..929be1d35af55acbce598eba578f91647ae79548 100644 --- a/modules/io/src/mol/sdf_writer.hh +++ b/modules/io/src/mol/sdf_writer.hh @@ -54,6 +54,7 @@ private: std::ostream& ostr_; int counter_; std::map<long,int> atom_indices_; + String filename_; }; }} diff --git a/modules/io/src/mol/star_parser.cc b/modules/io/src/mol/star_parser.cc index f22857a8ff2f4001ebc65cf704862fbc73db49b4..c16bc24831c4b1ab5128e7606544f0100a1b470b 100644 --- a/modules/io/src/mol/star_parser.cc +++ b/modules/io/src/mol/star_parser.cc @@ -549,9 +549,9 @@ void StarParser::ParseGlobal() void StarParser::Parse() { if (!file_open_) { - throw IOException(this->FormatDiagnostic(STAR_DIAG_ERROR, - "Failed to open file '" + - filename_ + "'!")); + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + filename_ + "'"); } StringRef line; std::stringstream ss; diff --git a/modules/io/src/mol/star_writer.cc b/modules/io/src/mol/star_writer.cc index 4b64bd370f4deb824bd72b7101a250472ca9c5b2..73ff08f9460c14db311a149cdc240ce19ffcd6b1 100644 --- a/modules/io/src/mol/star_writer.cc +++ b/modules/io/src/mol/star_writer.cc @@ -27,10 +27,9 @@ namespace ost{ namespace io{ void StarWriter::Write(const String& data_name, std::ostream& stream) { if(!stream) { - std::stringstream ss; - ss << "Cannot open stream: [Errno " << errno << "] " - << strerror(errno) << std::endl; - throw IOException(ss.str()); + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": <stream>"); } // write data header stream << "data_" << data_name << std::endl; @@ -45,10 +44,9 @@ void StarWriter::Write(const String& data_name, std::ostream& stream) { void StarWriter::Write(const String& data_name, const String& filename) { std::ofstream fstream(filename.c_str()); if (!fstream) { - std::stringstream ss; - ss << "Cannot open " << filename << ": [Errno " << errno << "] " - << strerror(errno) << std::endl; - throw IOException(ss.str()); + throw IOException("[Errno " + std::to_string(errno) + "] " + + std::string(strerror(errno)) + + ": '" + filename + "'"); } boost::iostreams::filtering_stream<boost::iostreams::output> stream; if (boost::iequals(".gz", boost::filesystem::extension(filename))) {