[英]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. 我正在使用boost 1.52,当我试图从我没有权限读取的网络驱动器中获取文件时。 I get an exception, after using
boost::filesystem::exists(fileName)
使用
boost::filesystem::exists(fileName)
后我得到一个异常
Is there a work around nicer than just doing try, catch
at every place? 有没有比仅仅
try, catch
更好的工作try, catch
在每个地方?
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());
}
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.
这取决于你想要完成的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.