diff --git a/src/lib/utility/text/TextAccess.cpp b/src/lib/utility/text/TextAccess.cpp index 535e12ae..a6cab716 100644 --- a/src/lib/utility/text/TextAccess.cpp +++ b/src/lib/utility/text/TextAccess.cpp @@ -138,22 +138,36 @@ std::vector TextAccess::readFile(const FilePath& filePath) { std::vector result; - std::ifstream srcFile; - srcFile.open(filePath.str()); - - if (srcFile.fail()) + try { - LOG_ERROR(L"Could not open file " + filePath.wstr()); - return result; - } + std::ifstream srcFile; + srcFile.open(filePath.str()); - while (!srcFile.eof()) + if (srcFile.fail()) + { + LOG_ERROR(L"Could not open file " + filePath.wstr()); + return result; + } + + while (!srcFile.eof()) + { + std::string line; + safeGetline(srcFile, line); + result.push_back(line + '\n'); + } + + srcFile.close(); + } + catch (std::exception& e) { - std::string line; - safeGetline(srcFile, line); - result.push_back(line + '\n'); + LOG_ERROR_STREAM(<< "Exception thrown while reading file \"" << filePath.str() << "\": " << e.what()); + result.clear(); + } + catch (...) + { + LOG_ERROR_STREAM(<< "Unknown exception thrown while reading file \"" << filePath.str() << "\""); + result.clear(); } - srcFile.close(); if (!result.empty()) {