Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::filesystem::exists crashs

I'm using boost 1.52, when i'm trying to get a file from a network drive that i don't have permissions to read from. I get an exception, after using boost::filesystem::exists(fileName)
Is there a work around nicer than just doing try, catch at every place?

I have switched back for my old code for now:

bool FileExists(const char* fileName)
{
    struct stat my_stat;
    return (stat(fileName, &my_stat) == 0);
}

//boost Exists throws exception if there are no permissions for share folder
bool FileExists(const std::string& fileName)
{
    return FileExists(fileName.c_str());
}
like image 627
Gilad Avatar asked Jan 22 '26 16:01

Gilad


1 Answers

Use the overload that does not throw.

bool exists(const path& p, system::error_code& ec) noexcept;

You will want to check the output parameter however, so this may be more work than catching an exception. It depends what you're trying to accomplish.

like image 55
Sam Miller Avatar answered Jan 25 '26 07:01

Sam Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!