Question

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());
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top