0

你们能帮我破译抛出的未知异常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(). 如果存在,则后续执行代码不会导致异常。

最糟糕的是,我看不到异常的原因。我只能捕捉到std::exceptionwhat()返回无意义的“std::exception”。

为了找出问题所在,我拼命地尝试输出typeid(ex).name()显示

N5boost16exception_detail10clone_implINS0_19error_info_injectorISt9exception

根据谷歌的意思是:boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> >

有什么想法有什么问题吗?

4

2 回答 2

1

经过 50 分钟的猜测,我发现问题出在length现场。文档没有说,但它的默认值必须是 -1,如源代码中所述

BOOST_STATIC_CONSTANT(size_type, max_length = static_cast<size_type>(-1));

我直观地假设,如果我设置new_file_size为大于零,它将忽略length.

于 2012-11-15T00:23:41.147 回答
1

您可以在调试器中运行代码并在实际引发异常的函数中设置断点,例如__cxa_throw. 您的系统上的函数名称可能不同:使用nm -po program | less并搜索包含throw. 在那些看起来最有可能是由系统创建的断点中设置一个断点。如果只有很少的异常被抛出,你也可以在std::exception::exception().

于 2012-11-14T23:51:49.123 回答