add error exception
This commit is contained in:
parent
dea68d7b33
commit
a7ec673c10
14
bin/main.cpp
14
bin/main.cpp
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user