diff --git a/src/utils.cc b/src/utils.cc index fec94328..be83fa04 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -229,11 +229,13 @@ std::istream& SafeGetline(std::istream& is, std::string& t) { optional ReadContent(const std::string& filename) { std::ifstream cache; cache.open(filename); - if (!cache.good()) - return nullopt; - return std::string(std::istreambuf_iterator(cache), - std::istreambuf_iterator()); + try { + return std::string(std::istreambuf_iterator(cache), + std::istreambuf_iterator()); + } catch (std::ios_base::failure&) { + return nullopt; + } } std::vector ReadLines(std::string filename) {