当我尝试从我无权读取的网络驱动器获取文件时,我正在使用 boost 1.52。使用后出现异常boost::filesystem::exists(fileName)
有没有比直接做更好的工作try, catch
在每个地方?
我现在已经切换回旧代码:
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());
}
Use the overload http://www.boost.org/doc/libs/1_52_0/libs/filesystem/doc/reference.html#exists那不会抛出。
bool exists(const path& p, system::error_code& ec) noexcept;
然而,您将需要检查输出参数,因此这可能比捕获异常需要更多工作。这取决于您想要实现的目标。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)