boost :: filesystem :: exists崩溃

时间:2013-03-10 17:03:07

标签: c++ boost boost-filesystem

我正在使用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());
}

1 个答案:

答案 0 :(得分:4)

使用不投掷的overload

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

但是,您需要检查输出参数,因此这可能比捕获异常更有用。这取决于你想要完成的事情。

相关问题