开发者

catching exception from boost::filesystem::is_directory

I am currently catching errors from boost::filesystem::is_directory and showing the error to the user by calling "what()" on the exception. This gives the reason for failure but 开发者_如何学Gothe error is strange to the user. For example:

boost::filesystem::is_directory: Access is denied

How can I catch the boost error and figure out what the actual cause is, so I can show a nicer error message?


By "nicer error message" would you mean something like

#include <iostream>
#include <boost/filesystem.hpp>
int main()
{
    boost::filesystem::path p("/proc/1/fd/1");
    try {
       boost::filesystem::is_directory(p);
    } catch(const boost::filesystem::filesystem_error& e)
    {
       if(e.code() == boost::system::errc::permission_denied)
           std::cout << "Search permission is denied for one of the directories "
                     << "in the path prefix of " << p << "\n";
       else
           std::cout << "is_directory(" << p << ") failed with "
                     << e.code().message() << '\n';
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜