1.1 --- a/lemon/lgf_reader.h Wed Oct 01 12:44:16 2008 +0200
1.2 +++ b/lemon/lgf_reader.h Wed Oct 01 13:56:40 2008 +0200
1.3 @@ -48,11 +48,13 @@
1.4 Value operator()(const std::string& str) {
1.5 std::istringstream is(str);
1.6 Value value;
1.7 - is >> value;
1.8 + if (!(is >> value)) {
1.9 + throw FormatError("Cannot read token");
1.10 + }
1.11
1.12 char c;
1.13 if (is >> std::ws >> c) {
1.14 - throw DataFormatError("Remaining characters in token");
1.15 + throw FormatError("Remaining characters in token");
1.16 }
1.17 return value;
1.18 }
1.19 @@ -166,7 +168,7 @@
1.20 if (it == _map.end()) {
1.21 std::ostringstream msg;
1.22 msg << "Item not found: " << str;
1.23 - throw DataFormatError(msg.str().c_str());
1.24 + throw FormatError(msg.str());
1.25 }
1.26 return it->second;
1.27 }
1.28 @@ -184,12 +186,12 @@
1.29
1.30 typename Graph::Arc operator()(const std::string& str) {
1.31 if (str.empty() || (str[0] != '+' && str[0] != '-')) {
1.32 - throw DataFormatError("Item must start with '+' or '-'");
1.33 + throw FormatError("Item must start with '+' or '-'");
1.34 }
1.35 typename std::map<std::string, typename Graph::Edge>
1.36 ::const_iterator it = _map.find(str.substr(1));
1.37 if (it == _map.end()) {
1.38 - throw DataFormatError("Item not found");
1.39 + throw FormatError("Item not found");
1.40 }
1.41 return _graph.direct(it->second, str[0] == '+');
1.42 }
1.43 @@ -235,7 +237,7 @@
1.44 inline char readEscape(std::istream& is) {
1.45 char c;
1.46 if (!is.get(c))
1.47 - throw DataFormatError("Escape format error");
1.48 + throw FormatError("Escape format error");
1.49
1.50 switch (c) {
1.51 case '\\':
1.52 @@ -264,7 +266,7 @@
1.53 {
1.54 int code;
1.55 if (!is.get(c) || !isHex(c))
1.56 - throw DataFormatError("Escape format error");
1.57 + throw FormatError("Escape format error");
1.58 else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
1.59 else code = code * 16 + valueHex(c);
1.60 return code;
1.61 @@ -273,7 +275,7 @@
1.62 {
1.63 int code;
1.64 if (!isOct(c))
1.65 - throw DataFormatError("Escape format error");
1.66 + throw FormatError("Escape format error");
1.67 else if (code = valueOct(c), !is.get(c) || !isOct(c))
1.68 is.putback(c);
1.69 else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
1.70 @@ -300,7 +302,7 @@
1.71 os << c;
1.72 }
1.73 if (!is)
1.74 - throw DataFormatError("Quoted format error");
1.75 + throw FormatError("Quoted format error");
1.76 } else {
1.77 is.putback(c);
1.78 while (is.get(c) && !isWhiteSpace(c)) {
1.79 @@ -461,6 +463,7 @@
1.80
1.81 std::istream* _is;
1.82 bool local_is;
1.83 + std::string _filename;
1.84
1.85 Digraph& _digraph;
1.86
1.87 @@ -510,18 +513,24 @@
1.88 /// Construct a directed graph reader, which reads from the given
1.89 /// file.
1.90 DigraphReader(Digraph& digraph, const std::string& fn)
1.91 - : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
1.92 + : _is(new std::ifstream(fn.c_str())), local_is(true),
1.93 + _filename(fn), _digraph(digraph),
1.94 _use_nodes(false), _use_arcs(false),
1.95 - _skip_nodes(false), _skip_arcs(false) {}
1.96 + _skip_nodes(false), _skip_arcs(false) {
1.97 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.98 + }
1.99
1.100 /// \brief Constructor
1.101 ///
1.102 /// Construct a directed graph reader, which reads from the given
1.103 /// file.
1.104 DigraphReader(Digraph& digraph, const char* fn)
1.105 - : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
1.106 + : _is(new std::ifstream(fn)), local_is(true),
1.107 + _filename(fn), _digraph(digraph),
1.108 _use_nodes(false), _use_arcs(false),
1.109 - _skip_nodes(false), _skip_arcs(false) {}
1.110 + _skip_nodes(false), _skip_arcs(false) {
1.111 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.112 + }
1.113
1.114 /// \brief Destructor
1.115 ~DigraphReader() {
1.116 @@ -846,7 +855,7 @@
1.117 if (!readLine() || !(line >> c) || c == '@') {
1.118 if (readSuccess() && line) line.putback(c);
1.119 if (!_node_maps.empty())
1.120 - throw DataFormatError("Cannot find map names");
1.121 + throw FormatError("Cannot find map names");
1.122 return;
1.123 }
1.124 line.putback(c);
1.125 @@ -860,7 +869,7 @@
1.126 if (maps.find(map) != maps.end()) {
1.127 std::ostringstream msg;
1.128 msg << "Multiple occurence of node map: " << map;
1.129 - throw DataFormatError(msg.str().c_str());
1.130 + throw FormatError(msg.str());
1.131 }
1.132 maps.insert(std::make_pair(map, index));
1.133 ++index;
1.134 @@ -871,8 +880,8 @@
1.135 maps.find(_node_maps[i].first);
1.136 if (jt == maps.end()) {
1.137 std::ostringstream msg;
1.138 - msg << "Map not found in file: " << _node_maps[i].first;
1.139 - throw DataFormatError(msg.str().c_str());
1.140 + msg << "Map not found: " << _node_maps[i].first;
1.141 + throw FormatError(msg.str());
1.142 }
1.143 map_index[i] = jt->second;
1.144 }
1.145 @@ -896,11 +905,11 @@
1.146 if (!_reader_bits::readToken(line, tokens[i])) {
1.147 std::ostringstream msg;
1.148 msg << "Column not found (" << i + 1 << ")";
1.149 - throw DataFormatError(msg.str().c_str());
1.150 + throw FormatError(msg.str());
1.151 }
1.152 }
1.153 if (line >> std::ws >> c)
1.154 - throw DataFormatError("Extra character on the end of line");
1.155 + throw FormatError("Extra character at the end of line");
1.156
1.157 Node n;
1.158 if (!_use_nodes) {
1.159 @@ -909,13 +918,13 @@
1.160 _node_index.insert(std::make_pair(tokens[label_index], n));
1.161 } else {
1.162 if (label_index == -1)
1.163 - throw DataFormatError("Label map not found in file");
1.164 + throw FormatError("Label map not found");
1.165 typename std::map<std::string, Node>::iterator it =
1.166 _node_index.find(tokens[label_index]);
1.167 if (it == _node_index.end()) {
1.168 std::ostringstream msg;
1.169 msg << "Node with label not found: " << tokens[label_index];
1.170 - throw DataFormatError(msg.str().c_str());
1.171 + throw FormatError(msg.str());
1.172 }
1.173 n = it->second;
1.174 }
1.175 @@ -939,7 +948,7 @@
1.176 if (!readLine() || !(line >> c) || c == '@') {
1.177 if (readSuccess() && line) line.putback(c);
1.178 if (!_arc_maps.empty())
1.179 - throw DataFormatError("Cannot find map names");
1.180 + throw FormatError("Cannot find map names");
1.181 return;
1.182 }
1.183 line.putback(c);
1.184 @@ -953,7 +962,7 @@
1.185 if (maps.find(map) != maps.end()) {
1.186 std::ostringstream msg;
1.187 msg << "Multiple occurence of arc map: " << map;
1.188 - throw DataFormatError(msg.str().c_str());
1.189 + throw FormatError(msg.str());
1.190 }
1.191 maps.insert(std::make_pair(map, index));
1.192 ++index;
1.193 @@ -964,8 +973,8 @@
1.194 maps.find(_arc_maps[i].first);
1.195 if (jt == maps.end()) {
1.196 std::ostringstream msg;
1.197 - msg << "Map not found in file: " << _arc_maps[i].first;
1.198 - throw DataFormatError(msg.str().c_str());
1.199 + msg << "Map not found: " << _arc_maps[i].first;
1.200 + throw FormatError(msg.str());
1.201 }
1.202 map_index[i] = jt->second;
1.203 }
1.204 @@ -988,21 +997,21 @@
1.205 std::string target_token;
1.206
1.207 if (!_reader_bits::readToken(line, source_token))
1.208 - throw DataFormatError("Source not found");
1.209 + throw FormatError("Source not found");
1.210
1.211 if (!_reader_bits::readToken(line, target_token))
1.212 - throw DataFormatError("Target not found");
1.213 + throw FormatError("Target not found");
1.214
1.215 std::vector<std::string> tokens(map_num);
1.216 for (int i = 0; i < map_num; ++i) {
1.217 if (!_reader_bits::readToken(line, tokens[i])) {
1.218 std::ostringstream msg;
1.219 msg << "Column not found (" << i + 1 << ")";
1.220 - throw DataFormatError(msg.str().c_str());
1.221 + throw FormatError(msg.str());
1.222 }
1.223 }
1.224 if (line >> std::ws >> c)
1.225 - throw DataFormatError("Extra character on the end of line");
1.226 + throw FormatError("Extra character at the end of line");
1.227
1.228 Arc a;
1.229 if (!_use_arcs) {
1.230 @@ -1013,7 +1022,7 @@
1.231 if (it == _node_index.end()) {
1.232 std::ostringstream msg;
1.233 msg << "Item not found: " << source_token;
1.234 - throw DataFormatError(msg.str().c_str());
1.235 + throw FormatError(msg.str());
1.236 }
1.237 Node source = it->second;
1.238
1.239 @@ -1021,7 +1030,7 @@
1.240 if (it == _node_index.end()) {
1.241 std::ostringstream msg;
1.242 msg << "Item not found: " << target_token;
1.243 - throw DataFormatError(msg.str().c_str());
1.244 + throw FormatError(msg.str());
1.245 }
1.246 Node target = it->second;
1.247
1.248 @@ -1030,13 +1039,13 @@
1.249 _arc_index.insert(std::make_pair(tokens[label_index], a));
1.250 } else {
1.251 if (label_index == -1)
1.252 - throw DataFormatError("Label map not found in file");
1.253 + throw FormatError("Label map not found");
1.254 typename std::map<std::string, Arc>::iterator it =
1.255 _arc_index.find(tokens[label_index]);
1.256 if (it == _arc_index.end()) {
1.257 std::ostringstream msg;
1.258 msg << "Arc with label not found: " << tokens[label_index];
1.259 - throw DataFormatError(msg.str().c_str());
1.260 + throw FormatError(msg.str());
1.261 }
1.262 a = it->second;
1.263 }
1.264 @@ -1061,18 +1070,18 @@
1.265
1.266 std::string attr, token;
1.267 if (!_reader_bits::readToken(line, attr))
1.268 - throw DataFormatError("Attribute name not found");
1.269 + throw FormatError("Attribute name not found");
1.270 if (!_reader_bits::readToken(line, token))
1.271 - throw DataFormatError("Attribute value not found");
1.272 + throw FormatError("Attribute value not found");
1.273 if (line >> c)
1.274 - throw DataFormatError("Extra character on the end of line");
1.275 + throw FormatError("Extra character at the end of line");
1.276
1.277 {
1.278 std::set<std::string>::iterator it = read_attr.find(attr);
1.279 if (it != read_attr.end()) {
1.280 std::ostringstream msg;
1.281 - msg << "Multiple occurence of attribute " << attr;
1.282 - throw DataFormatError(msg.str().c_str());
1.283 + msg << "Multiple occurence of attribute: " << attr;
1.284 + throw FormatError(msg.str());
1.285 }
1.286 read_attr.insert(attr);
1.287 }
1.288 @@ -1093,8 +1102,8 @@
1.289 it != _attributes.end(); ++it) {
1.290 if (read_attr.find(it->first) == read_attr.end()) {
1.291 std::ostringstream msg;
1.292 - msg << "Attribute not found in file: " << it->first;
1.293 - throw DataFormatError(msg.str().c_str());
1.294 + msg << "Attribute not found: " << it->first;
1.295 + throw FormatError(msg.str());
1.296 }
1.297 }
1.298 }
1.299 @@ -1109,9 +1118,6 @@
1.300 /// This function starts the batch processing
1.301 void run() {
1.302 LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
1.303 - if (!*_is) {
1.304 - throw DataFormatError("Cannot find file");
1.305 - }
1.306
1.307 bool nodes_done = _skip_nodes;
1.308 bool arcs_done = _skip_arcs;
1.309 @@ -1130,7 +1136,7 @@
1.310 _reader_bits::readToken(line, caption);
1.311
1.312 if (line >> c)
1.313 - throw DataFormatError("Extra character on the end of line");
1.314 + throw FormatError("Extra character at the end of line");
1.315
1.316 if (section == "nodes" && !nodes_done) {
1.317 if (_nodes_caption.empty() || _nodes_caption == caption) {
1.318 @@ -1152,22 +1158,23 @@
1.319 readLine();
1.320 skipSection();
1.321 }
1.322 - } catch (DataFormatError& error) {
1.323 + } catch (FormatError& error) {
1.324 error.line(line_num);
1.325 + error.file(_filename);
1.326 throw;
1.327 }
1.328 }
1.329
1.330 if (!nodes_done) {
1.331 - throw DataFormatError("Section @nodes not found");
1.332 + throw FormatError("Section @nodes not found");
1.333 }
1.334
1.335 if (!arcs_done) {
1.336 - throw DataFormatError("Section @arcs not found");
1.337 + throw FormatError("Section @arcs not found");
1.338 }
1.339
1.340 if (!attributes_done && !_attributes.empty()) {
1.341 - throw DataFormatError("Section @attributes not found");
1.342 + throw FormatError("Section @attributes not found");
1.343 }
1.344
1.345 }
1.346 @@ -1247,6 +1254,7 @@
1.347
1.348 std::istream* _is;
1.349 bool local_is;
1.350 + std::string _filename;
1.351
1.352 Graph& _graph;
1.353
1.354 @@ -1296,18 +1304,24 @@
1.355 /// Construct an undirected graph reader, which reads from the given
1.356 /// file.
1.357 GraphReader(Graph& graph, const std::string& fn)
1.358 - : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
1.359 + : _is(new std::ifstream(fn.c_str())), local_is(true),
1.360 + _filename(fn), _graph(graph),
1.361 _use_nodes(false), _use_edges(false),
1.362 - _skip_nodes(false), _skip_edges(false) {}
1.363 + _skip_nodes(false), _skip_edges(false) {
1.364 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.365 + }
1.366
1.367 /// \brief Constructor
1.368 ///
1.369 /// Construct an undirected graph reader, which reads from the given
1.370 /// file.
1.371 GraphReader(Graph& graph, const char* fn)
1.372 - : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
1.373 + : _is(new std::ifstream(fn)), local_is(true),
1.374 + _filename(fn), _graph(graph),
1.375 _use_nodes(false), _use_edges(false),
1.376 - _skip_nodes(false), _skip_edges(false) {}
1.377 + _skip_nodes(false), _skip_edges(false) {
1.378 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.379 + }
1.380
1.381 /// \brief Destructor
1.382 ~GraphReader() {
1.383 @@ -1676,7 +1690,7 @@
1.384 if (!readLine() || !(line >> c) || c == '@') {
1.385 if (readSuccess() && line) line.putback(c);
1.386 if (!_node_maps.empty())
1.387 - throw DataFormatError("Cannot find map names");
1.388 + throw FormatError("Cannot find map names");
1.389 return;
1.390 }
1.391 line.putback(c);
1.392 @@ -1690,7 +1704,7 @@
1.393 if (maps.find(map) != maps.end()) {
1.394 std::ostringstream msg;
1.395 msg << "Multiple occurence of node map: " << map;
1.396 - throw DataFormatError(msg.str().c_str());
1.397 + throw FormatError(msg.str());
1.398 }
1.399 maps.insert(std::make_pair(map, index));
1.400 ++index;
1.401 @@ -1701,8 +1715,8 @@
1.402 maps.find(_node_maps[i].first);
1.403 if (jt == maps.end()) {
1.404 std::ostringstream msg;
1.405 - msg << "Map not found in file: " << _node_maps[i].first;
1.406 - throw DataFormatError(msg.str().c_str());
1.407 + msg << "Map not found: " << _node_maps[i].first;
1.408 + throw FormatError(msg.str());
1.409 }
1.410 map_index[i] = jt->second;
1.411 }
1.412 @@ -1726,11 +1740,11 @@
1.413 if (!_reader_bits::readToken(line, tokens[i])) {
1.414 std::ostringstream msg;
1.415 msg << "Column not found (" << i + 1 << ")";
1.416 - throw DataFormatError(msg.str().c_str());
1.417 + throw FormatError(msg.str());
1.418 }
1.419 }
1.420 if (line >> std::ws >> c)
1.421 - throw DataFormatError("Extra character on the end of line");
1.422 + throw FormatError("Extra character at the end of line");
1.423
1.424 Node n;
1.425 if (!_use_nodes) {
1.426 @@ -1739,13 +1753,13 @@
1.427 _node_index.insert(std::make_pair(tokens[label_index], n));
1.428 } else {
1.429 if (label_index == -1)
1.430 - throw DataFormatError("Label map not found in file");
1.431 + throw FormatError("Label map not found");
1.432 typename std::map<std::string, Node>::iterator it =
1.433 _node_index.find(tokens[label_index]);
1.434 if (it == _node_index.end()) {
1.435 std::ostringstream msg;
1.436 msg << "Node with label not found: " << tokens[label_index];
1.437 - throw DataFormatError(msg.str().c_str());
1.438 + throw FormatError(msg.str());
1.439 }
1.440 n = it->second;
1.441 }
1.442 @@ -1769,7 +1783,7 @@
1.443 if (!readLine() || !(line >> c) || c == '@') {
1.444 if (readSuccess() && line) line.putback(c);
1.445 if (!_edge_maps.empty())
1.446 - throw DataFormatError("Cannot find map names");
1.447 + throw FormatError("Cannot find map names");
1.448 return;
1.449 }
1.450 line.putback(c);
1.451 @@ -1783,7 +1797,7 @@
1.452 if (maps.find(map) != maps.end()) {
1.453 std::ostringstream msg;
1.454 msg << "Multiple occurence of edge map: " << map;
1.455 - throw DataFormatError(msg.str().c_str());
1.456 + throw FormatError(msg.str());
1.457 }
1.458 maps.insert(std::make_pair(map, index));
1.459 ++index;
1.460 @@ -1794,8 +1808,8 @@
1.461 maps.find(_edge_maps[i].first);
1.462 if (jt == maps.end()) {
1.463 std::ostringstream msg;
1.464 - msg << "Map not found in file: " << _edge_maps[i].first;
1.465 - throw DataFormatError(msg.str().c_str());
1.466 + msg << "Map not found: " << _edge_maps[i].first;
1.467 + throw FormatError(msg.str());
1.468 }
1.469 map_index[i] = jt->second;
1.470 }
1.471 @@ -1818,21 +1832,21 @@
1.472 std::string target_token;
1.473
1.474 if (!_reader_bits::readToken(line, source_token))
1.475 - throw DataFormatError("Node u not found");
1.476 + throw FormatError("Node u not found");
1.477
1.478 if (!_reader_bits::readToken(line, target_token))
1.479 - throw DataFormatError("Node v not found");
1.480 + throw FormatError("Node v not found");
1.481
1.482 std::vector<std::string> tokens(map_num);
1.483 for (int i = 0; i < map_num; ++i) {
1.484 if (!_reader_bits::readToken(line, tokens[i])) {
1.485 std::ostringstream msg;
1.486 msg << "Column not found (" << i + 1 << ")";
1.487 - throw DataFormatError(msg.str().c_str());
1.488 + throw FormatError(msg.str());
1.489 }
1.490 }
1.491 if (line >> std::ws >> c)
1.492 - throw DataFormatError("Extra character on the end of line");
1.493 + throw FormatError("Extra character at the end of line");
1.494
1.495 Edge e;
1.496 if (!_use_edges) {
1.497 @@ -1843,7 +1857,7 @@
1.498 if (it == _node_index.end()) {
1.499 std::ostringstream msg;
1.500 msg << "Item not found: " << source_token;
1.501 - throw DataFormatError(msg.str().c_str());
1.502 + throw FormatError(msg.str());
1.503 }
1.504 Node source = it->second;
1.505
1.506 @@ -1851,7 +1865,7 @@
1.507 if (it == _node_index.end()) {
1.508 std::ostringstream msg;
1.509 msg << "Item not found: " << target_token;
1.510 - throw DataFormatError(msg.str().c_str());
1.511 + throw FormatError(msg.str());
1.512 }
1.513 Node target = it->second;
1.514
1.515 @@ -1860,13 +1874,13 @@
1.516 _edge_index.insert(std::make_pair(tokens[label_index], e));
1.517 } else {
1.518 if (label_index == -1)
1.519 - throw DataFormatError("Label map not found in file");
1.520 + throw FormatError("Label map not found");
1.521 typename std::map<std::string, Edge>::iterator it =
1.522 _edge_index.find(tokens[label_index]);
1.523 if (it == _edge_index.end()) {
1.524 std::ostringstream msg;
1.525 msg << "Edge with label not found: " << tokens[label_index];
1.526 - throw DataFormatError(msg.str().c_str());
1.527 + throw FormatError(msg.str());
1.528 }
1.529 e = it->second;
1.530 }
1.531 @@ -1891,18 +1905,18 @@
1.532
1.533 std::string attr, token;
1.534 if (!_reader_bits::readToken(line, attr))
1.535 - throw DataFormatError("Attribute name not found");
1.536 + throw FormatError("Attribute name not found");
1.537 if (!_reader_bits::readToken(line, token))
1.538 - throw DataFormatError("Attribute value not found");
1.539 + throw FormatError("Attribute value not found");
1.540 if (line >> c)
1.541 - throw DataFormatError("Extra character on the end of line");
1.542 + throw FormatError("Extra character at the end of line");
1.543
1.544 {
1.545 std::set<std::string>::iterator it = read_attr.find(attr);
1.546 if (it != read_attr.end()) {
1.547 std::ostringstream msg;
1.548 - msg << "Multiple occurence of attribute " << attr;
1.549 - throw DataFormatError(msg.str().c_str());
1.550 + msg << "Multiple occurence of attribute: " << attr;
1.551 + throw FormatError(msg.str());
1.552 }
1.553 read_attr.insert(attr);
1.554 }
1.555 @@ -1923,8 +1937,8 @@
1.556 it != _attributes.end(); ++it) {
1.557 if (read_attr.find(it->first) == read_attr.end()) {
1.558 std::ostringstream msg;
1.559 - msg << "Attribute not found in file: " << it->first;
1.560 - throw DataFormatError(msg.str().c_str());
1.561 + msg << "Attribute not found: " << it->first;
1.562 + throw FormatError(msg.str());
1.563 }
1.564 }
1.565 }
1.566 @@ -1958,7 +1972,7 @@
1.567 _reader_bits::readToken(line, caption);
1.568
1.569 if (line >> c)
1.570 - throw DataFormatError("Extra character on the end of line");
1.571 + throw FormatError("Extra character at the end of line");
1.572
1.573 if (section == "nodes" && !nodes_done) {
1.574 if (_nodes_caption.empty() || _nodes_caption == caption) {
1.575 @@ -1980,22 +1994,23 @@
1.576 readLine();
1.577 skipSection();
1.578 }
1.579 - } catch (DataFormatError& error) {
1.580 + } catch (FormatError& error) {
1.581 error.line(line_num);
1.582 + error.file(_filename);
1.583 throw;
1.584 }
1.585 }
1.586
1.587 if (!nodes_done) {
1.588 - throw DataFormatError("Section @nodes not found");
1.589 + throw FormatError("Section @nodes not found");
1.590 }
1.591
1.592 if (!edges_done) {
1.593 - throw DataFormatError("Section @edges not found");
1.594 + throw FormatError("Section @edges not found");
1.595 }
1.596
1.597 if (!attributes_done && !_attributes.empty()) {
1.598 - throw DataFormatError("Section @attributes not found");
1.599 + throw FormatError("Section @attributes not found");
1.600 }
1.601
1.602 }
1.603 @@ -2056,6 +2071,7 @@
1.604
1.605 std::istream* _is;
1.606 bool local_is;
1.607 + std::string _filename;
1.608
1.609 typedef std::map<std::string, _reader_bits::Section*> Sections;
1.610 Sections _sections;
1.611 @@ -2076,13 +2092,19 @@
1.612 ///
1.613 /// Construct a section reader, which reads from the given file.
1.614 SectionReader(const std::string& fn)
1.615 - : _is(new std::ifstream(fn.c_str())), local_is(true) {}
1.616 + : _is(new std::ifstream(fn.c_str())), local_is(true),
1.617 + _filename(fn) {
1.618 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.619 + }
1.620
1.621 /// \brief Constructor
1.622 ///
1.623 /// Construct a section reader, which reads from the given file.
1.624 SectionReader(const char* fn)
1.625 - : _is(new std::ifstream(fn)), local_is(true) {}
1.626 + : _is(new std::ifstream(fn)), local_is(true),
1.627 + _filename(fn) {
1.628 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.629 + }
1.630
1.631 /// \brief Destructor
1.632 ~SectionReader() {
1.633 @@ -2238,12 +2260,12 @@
1.634 _reader_bits::readToken(line, caption);
1.635
1.636 if (line >> c)
1.637 - throw DataFormatError("Extra character on the end of line");
1.638 + throw FormatError("Extra character at the end of line");
1.639
1.640 if (extra_sections.find(section) != extra_sections.end()) {
1.641 std::ostringstream msg;
1.642 - msg << "Multiple occurence of section " << section;
1.643 - throw DataFormatError(msg.str().c_str());
1.644 + msg << "Multiple occurence of section: " << section;
1.645 + throw FormatError(msg.str());
1.646 }
1.647 Sections::iterator it = _sections.find(section);
1.648 if (it != _sections.end()) {
1.649 @@ -2252,8 +2274,9 @@
1.650 }
1.651 readLine();
1.652 skipSection();
1.653 - } catch (DataFormatError& error) {
1.654 + } catch (FormatError& error) {
1.655 error.line(line_num);
1.656 + error.file(_filename);
1.657 throw;
1.658 }
1.659 }
1.660 @@ -2262,7 +2285,7 @@
1.661 if (extra_sections.find(it->first) == extra_sections.end()) {
1.662 std::ostringstream os;
1.663 os << "Cannot find section: " << it->first;
1.664 - throw DataFormatError(os.str().c_str());
1.665 + throw FormatError(os.str());
1.666 }
1.667 }
1.668 }
1.669 @@ -2362,14 +2385,18 @@
1.670 /// Construct an \e LGF contents reader, which reads from the given
1.671 /// file.
1.672 LgfContents(const std::string& fn)
1.673 - : _is(new std::ifstream(fn.c_str())), local_is(true) {}
1.674 + : _is(new std::ifstream(fn.c_str())), local_is(true) {
1.675 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.676 + }
1.677
1.678 /// \brief Constructor
1.679 ///
1.680 /// Construct an \e LGF contents reader, which reads from the given
1.681 /// file.
1.682 LgfContents(const char* fn)
1.683 - : _is(new std::ifstream(fn)), local_is(true) {}
1.684 + : _is(new std::ifstream(fn)), local_is(true) {
1.685 + if (!(*_is)) throw IoError("Cannot open file", fn);
1.686 + }
1.687
1.688 /// \brief Destructor
1.689 ~LgfContents() {