【发布时间】:2012-11-14 23:27:18
【问题描述】:
你们能帮我破译boost::iostreams::mapped_file_sink 抛出的未知异常吗?
我的配置
- 提升 1.51
- Windows 7 上的 Visual Studio 2012
- Ubuntu 上的 GCC 4.7
这是我的代码
try
{
boost::iostreams::mapped_file_params params_;
boost::iostreams::mapped_file_sink sink_;
params_.length = 0;
params_.new_file_size = 1024;
params_.path = "./test.bin";
sink_.open(params_);
sink_.close();
}
catch (std::ios::failure& ex)
{
std::cout << "\t" << "what: " << ex.what() << "\n";
}
catch (std::system_error& ex)
{
std::cout << "\t" << "code: " << ex.code() << " what: " << ex.what() << "\n";
}
catch (std::runtime_error& ex)
{
std::cout << "\t" << ex.what() << "\n";
}
catch (boost::archive::archive_exception& ex)
{
std::cout << "\t" << ex.what() << "\n";
}
catch (boost::exception& ex)
{
std::cout << "blah\n";
}
catch (std::exception& ex)
{
std::cout << "\t" << ex.what() << " --- " << typeid(ex).name() << "\n";
}
它总是在 Windows 中工作。
在 Ubuntu 中,它会创建给定大小的空文件,但会在 open() 上引发异常。后续执行代码if存在不会导致异常。
最糟糕的是我看不到异常的原因。我只能捕获std::exception 的what() 返回无意义的“std::exception”。
为了找出问题所在,我输出了typeid(ex).name(),这表明
N5boost16exception_detail10clone_implINS0_19error_info_injectorISt9exception
根据谷歌的意思是:boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> >
有什么想法吗?
【问题讨论】:
标签: c++ linux exception boost memory-mapped-files