mirror of
https://github.com/aristocratos/btop.git
synced 2024-06-02 10:35:14 +12:00
Added: ifstream check and try-catch for stod() in Tools::system_uptime()
This commit is contained in:
parent
5ae05f0333
commit
528df4d84f
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue