Added: ifstream check and try-catch for stod() in Tools::system_uptime()

This commit is contained in:
aristocratos 2021-09-26 01:03:57 +02:00
parent 5ae05f0333
commit 528df4d84f

View file

@ -1611,8 +1611,15 @@ namespace Tools {
double system_uptime() {
string upstr;
ifstream pread(Shared::procPath / "uptime");
getline(pread, upstr, ' ');
pread.close();
return stod(upstr);
if (pread.good()) {
try {
getline(pread, upstr, ' ');
pread.close();
return stod(upstr);
}
catch (const std::invalid_argument&) {}
catch (const std::out_of_range&) {}
}
throw std::runtime_error("Failed get uptime from from " + (string)Shared::procPath + "/uptime");
}
}