boost::filesystem::exists crashs

元气小坏坏 提交于 2019-12-23 19:19:49

问题


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());
}

回答1:


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.



来源:https://stackoverflow.com/questions/15324947/boostfilesystemexists-crashs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!