From a46234b7a5c69d6ba960bab3af59165fee801b0f Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Sat, 7 May 2011 00:41:17 +0200 Subject: [PATCH] issue better error when PDBWriter can't create the file --- modules/io/src/mol/pdb_writer.cc | 15 ++++++++++++--- modules/io/src/mol/pdb_writer.hh | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc index 8878fb16d..98022a0a5 100644 --- a/modules/io/src/mol/pdb_writer.cc +++ b/modules/io/src/mol/pdb_writer.cc @@ -339,13 +339,14 @@ PDBWriter::PDBWriter(const boost::filesystem::path& filename, #endif mol_count_(0), line_(80), multi_model_(false), charmm_style_(profile.dialect=="CHARMM"), is_pqr_(false), - profile_(profile) -{} + profile_(profile), filename_("") +{ +} PDBWriter::PDBWriter(const String& filename, const IOProfile& profile): outfile_(filename.c_str()), outstream_(outfile_), mol_count_(0), line_(80), multi_model_(false), charmm_style_(profile.dialect=="CHARMM"), - is_pqr_(false), profile_(profile) + is_pqr_(false), profile_(profile), filename_(filename) {} void PDBWriter::WriteModelLeader() @@ -368,6 +369,14 @@ void PDBWriter::WriteModelTrailer() template <typename H> void PDBWriter::WriteModel(H ent) { + if (!outstream_) { + if (!filename_.empty()) { + std::stringstream ss; + ss << "Can't write PDB to file '" << filename_ << "'"; + throw IOException(ss.str()); + } + throw IOException("Can't write PDB. Bad stream"); + } ForcePOSIX posix; this->WriteModelLeader(); PDBWriterImpl writer(outstream_,line_, atom_indices_, charmm_style_); diff --git a/modules/io/src/mol/pdb_writer.hh b/modules/io/src/mol/pdb_writer.hh index c849fd279..b0e70a89f 100644 --- a/modules/io/src/mol/pdb_writer.hh +++ b/modules/io/src/mol/pdb_writer.hh @@ -75,6 +75,7 @@ private: bool charmm_style_; bool is_pqr_; IOProfile profile_; + String filename_; }; }} -- GitLab