boost :: filesystem :: exists崩溃 [英] boost::filesystem::exists crashs

查看:755
本文介绍了boost :: filesystem :: exists崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图从网络驱动器中获取我没有读取权限的文件时,我使用的是Boost 1.52.使用boost::filesystem::exists(fileName)后出现异常
有没有比在每个地方都做try, catch更好的工作了?

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

推荐答案

使用不会抛出超载.

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.

这篇关于boost :: filesystem :: exists崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆