add error exception

This commit is contained in:
chatlanin 2023-04-19 21:18:15 +03:00
parent dea68d7b33
commit a7ec673c10

View File

@ -33,10 +33,13 @@ std::string get_size_string(const T& size)
auto main() -> int
{
std::ifstream fs("/etc/mtab");
try
{
std::FILE* file = std::fopen("/etc/fstab", "r");
struct mntent* mount_entry = nullptr;
if (file == nullptr)
throw std::runtime_error("File not found");
struct mntent* mount_entry = nullptr;
std::cout << "\n\n";
while ((mount_entry = getmntent(file)))
{
@ -62,5 +65,10 @@ auto main() -> int
}
std::fclose(file);
fs.close();
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
return 1;
}
}