diff --git a/lemon/lgf_writer.h b/lemon/lgf_writer.h --- a/lemon/lgf_writer.h +++ b/lemon/lgf_writer.h @@ -55,7 +55,7 @@ template bool operator<(const T&, const T&) { - throw DataFormatError("Label map is not comparable"); + throw FormatError("Label map is not comparable"); } template @@ -203,7 +203,7 @@ typename std::map::const_iterator it = _map.find(str); if (it == _map.end()) { - throw DataFormatError("Item not found"); + throw FormatError("Item not found"); } return it->second; } @@ -223,7 +223,7 @@ typename std::map ::const_iterator it = _map.find(val); if (it == _map.end()) { - throw DataFormatError("Item not found"); + throw FormatError("Item not found"); } return (_graph.direction(val) ? '+' : '-') + it->second; } @@ -462,7 +462,9 @@ /// output file. DigraphWriter(const Digraph& digraph, const std::string& fn) : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), - _skip_nodes(false), _skip_arcs(false) {} + _skip_nodes(false), _skip_arcs(false) { + if (!(*_os)) throw IoError("Cannot write file", fn); + } /// \brief Constructor /// @@ -470,7 +472,9 @@ /// output file. DigraphWriter(const Digraph& digraph, const char* fn) : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), - _skip_nodes(false), _skip_arcs(false) {} + _skip_nodes(false), _skip_arcs(false) { + if (!(*_os)) throw IoError("Cannot write file", fn); + } /// \brief Destructor ~DigraphWriter() { @@ -1019,7 +1023,9 @@ /// output file. GraphWriter(const Graph& graph, const std::string& fn) : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), - _skip_nodes(false), _skip_edges(false) {} + _skip_nodes(false), _skip_edges(false) { + if (!(*_os)) throw IoError("Cannot write file", fn); + } /// \brief Constructor /// @@ -1027,7 +1033,9 @@ /// output file. GraphWriter(const Graph& graph, const char* fn) : _os(new std::ofstream(fn)), local_os(true), _graph(graph), - _skip_nodes(false), _skip_edges(false) {} + _skip_nodes(false), _skip_edges(false) { + if (!(*_os)) throw IoError("Cannot write file", fn); + } /// \brief Destructor ~GraphWriter() { @@ -1578,13 +1586,17 @@ /// /// Construct a section writer, which writes into the given file. SectionWriter(const std::string& fn) - : _os(new std::ofstream(fn.c_str())), local_os(true) {} + : _os(new std::ofstream(fn.c_str())), local_os(true) { + if (!(*_os)) throw IoError("Cannot write file", fn); + } /// \brief Constructor /// /// Construct a section writer, which writes into the given file. SectionWriter(const char* fn) - : _os(new std::ofstream(fn)), local_os(true) {} + : _os(new std::ofstream(fn)), local_os(true) { + if (!(*_os)) throw IoError("Cannot write file", fn); + } /// \brief Destructor ~SectionWriter() {