diff --git a/src/Navaids/fixlist.cxx b/src/Navaids/fixlist.cxx index 02506cb87..98e40eb17 100644 --- a/src/Navaids/fixlist.cxx +++ b/src/Navaids/fixlist.cxx @@ -29,6 +29,7 @@ #include #include // std::getline() +#include #include #include @@ -69,9 +70,11 @@ void FixesLoader::loadFixes(const SGPath& path) } // toss the first two lines of the file - in >> skipeol; - in >> skipeol; - + for (int i = 0; i < 2; i++) { + in >> skipeol; + throwExceptionIfStreamError(in, path); + } + unsigned int lineNumber = 3; // read in each remaining line of the file @@ -109,6 +112,21 @@ void FixesLoader::loadFixes(const SGPath& path) } } + throwExceptionIfStreamError(in, path); } +void FixesLoader::throwExceptionIfStreamError( + const sg_gzifstream& input_stream, const SGPath& path) +{ + if (input_stream.bad()) { + const std::string errMsg = simgear::strutils::error_string(errno); + + SG_LOG(SG_NAVAID, SG_ALERT, + "Error while reading '" << path.utf8Str() << "': " << errMsg); + throw sg_io_exception("Error reading file (" + errMsg + ")", + sg_location(path)); + } +} + + } // of namespace flightgear; diff --git a/src/Navaids/fixlist.hxx b/src/Navaids/fixlist.hxx index 2ac760f0f..3182030de 100644 --- a/src/Navaids/fixlist.hxx +++ b/src/Navaids/fixlist.hxx @@ -28,6 +28,7 @@ #include class SGPath; +class sg_gzifstream; namespace flightgear { @@ -43,6 +44,9 @@ namespace flightgear void loadFixes(const SGPath& path); private: + void throwExceptionIfStreamError(const sg_gzifstream& input_stream, + const SGPath& path); + NavDataCache* _cache; }; }