diff --git a/modules/conop/src/chemdict_tool.cc b/modules/conop/src/chemdict_tool.cc index 28e0a2d703d1918e873ac4ca9095c24d801ff132..94668818bd5ca24dcab1e7f82052c523d8db715c 100644 --- a/modules/conop/src/chemdict_tool.cc +++ b/modules/conop/src/chemdict_tool.cc @@ -89,34 +89,40 @@ int main(int argc, char const *argv[]) if (boost::iequals(".gz", boost::filesystem::extension(argv[2]))) { filtered_istream.push(boost::iostreams::gzip_decompressor()); } - filtered_istream.push(istream); - io::ChemdictParser cdp(filtered_istream, dialect, ignore_reserved, ignore_obsolete); - conop::CompoundLibPtr compound_lib; - bool in_mem=false; - if (!strncmp(argv[1], "create", 6)) { - compound_lib=conop::CompoundLib::Create(":memory:"); - in_mem=true; - } else if (!strncmp(argv[1], "update", 6)) { - compound_lib=conop::CompoundLib::Load(argv[3]); - } else { - PrintUsage(); - return 0; - } - if (!compound_lib) { - return 0; + filtered_istream.push(istream); + try { + io::ChemdictParser cdp(filtered_istream, dialect, ignore_reserved, ignore_obsolete); + conop::CompoundLibPtr compound_lib; + bool in_mem=false; + if (!strncmp(argv[1], "create", 6)) { + compound_lib=conop::CompoundLib::Create(":memory:"); + in_mem=true; + } else if (!strncmp(argv[1], "update", 6)) { + compound_lib=conop::CompoundLib::Load(argv[3]); + } else { + PrintUsage(); + return 0; + } + if (!compound_lib) { + return 0; + } + assert(compound_lib); + conop::CompoundLibPtr in_mem_lib=in_mem ? compound_lib : + compound_lib->Copy(":memory:"); + compound_lib.reset(); + cdp.SetCompoundLib(in_mem_lib); + cdp.Parse(); + in_mem_lib->SetChemLibInfo(); + conop::CompoundLibPtr copy = in_mem_lib->Copy(argv[3]); + if (! copy) { + std::cout << "Cannot save " << argv[3] << ": [Errno " << errno << "] " + << strerror(errno) << std::endl; + return 1; + } } - assert(compound_lib); - conop::CompoundLibPtr in_mem_lib=in_mem ? compound_lib : - compound_lib->Copy(":memory:"); - compound_lib.reset(); - cdp.SetCompoundLib(in_mem_lib); - cdp.Parse(); - in_mem_lib->SetChemLibInfo(); - conop::CompoundLibPtr copy = in_mem_lib->Copy(argv[3]); - if (! copy) { - std::cout << "Cannot save " << argv[3] << ": [Errno " << errno << "] " - << strerror(errno) << std::endl; - return 1; + catch (ost::Error const &err) { + std::cerr << "Error: " << err.what() << std::endl; + return 1; } return 0; } diff --git a/modules/conop/src/compound.hh b/modules/conop/src/compound.hh index 1b0eb1cd5e54f80e7d0bcab44a7b88ca0c36c6d2..69c11d69ea4064f3c78dd7e749b9da44d7a8d532 100644 --- a/modules/conop/src/compound.hh +++ b/modules/conop/src/compound.hh @@ -23,6 +23,8 @@ #include <map> #include <boost/shared_ptr.hpp> #include <ost/string_ref.hh> +#include <ost/message.hh> +#include <ost/log.hh> #include <ost/conop/module_config.hh> #include <ost/mol/chem_class.hh> @@ -54,19 +56,27 @@ struct DLLEXPORT_OST_CONOP Date { static Date FromString(const StringRef& str) { std::vector<StringRef> parts=str.split('-'); - assert(parts.size()==3); + if (parts.size() != 3) { + std::stringstream msg; + msg << "Invalid date string: '" << str << "'"; + throw ost::Error(msg.str()); + } std::pair<bool, int> year=parts[0].to_int(); std::pair<bool, int> month=parts[1].to_int(); std::pair<bool, int> day=parts[2].to_int(); - assert(year.first); assert(month.first); assert(day.first); + if (! year.first || ! month.first || ! day.first) { + std::stringstream msg; + msg << "Invalid date string: '" << str << "'"; + throw ost::Error(msg.str()); + } return Date(year.second, month.second, day.second); } - + String ToString() const; int year; int month; - int day; + int day; }; struct DLLEXPORT_OST_CONOP AtomSpec {