简体   繁体   English

boost :: iostreams :: mapped_file_sink抛出未知异常

[英]boost::iostreams::mapped_file_sink throws unknown exception

Could you guys help me decypher unknown exception that is thrown by boost::iostreams::mapped_file_sink ? 你能帮我解决由boost::iostreams::mapped_file_sink抛出的decypher未知异常吗?

My configuration 我的配置

  • boost 1.51 提升1.51
  • Visual Studio 2012 on Windows 7 Windows 7上的Visual Studio 2012
  • GCC 4.7 on Ubuntu 关于Ubuntu的GCC 4.7

Here is the code I have 这是我的代码

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";
}

It always works in Windows. 它始终适用于Windows。

In Ubuntu it creates empty file of given size but throws exception on open() . 在Ubuntu中,它创建给定大小的空文件,但在open()上抛出异常。 Subsequent execution of the code if exists doesn't cause exception. 如果存在,则后续执行代码不会导致异常。

The worst part is that I can't see the reason of the exception. 最糟糕的是我无法看到异常的原因。 I can only catch std::exception whose what() returns meaningless "std::exception". 我只能捕获std::exceptionwhat()返回无意义的“std :: exception”。

In desperate attempt to find out what's wrong I output typeid(ex).name() which shows 在绝望的尝试找出什么是错的我输出显示的typeid(ex).name()

N5boost16exception_detail10clone_implINS0_19error_info_injectorISt9exception

which according to Google means: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> > 根据谷歌的意思: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> >

Any ideas what's wrong? 有什么想法有什么不对吗?

You could run the code in a debugger and set a breakpoint in the function which actually throws an exceptions, eg, __cxa_throw . 您可以在调试器中运行代码并在函数中设置断点,该断点实际上会抛出异常,例如__cxa_throw The name of the function may be different on your system: use nm -po program | less 您的系统上的功能名称可能有所不同:使用nm -po program | less nm -po program | less and search for a function containing throw . nm -po program | less并搜索包含throw的函数。 Set a breakpoint in the one(s) which look most likely as if they are created by the system. 在一个(或多个)中设置一个断点,看起来很可能就像它们是由系统创建的。 If there are only few exceptions being thrown, you can also set a breakpoint into std::exception::exception() . 如果抛出的异常很少,您还可以将断点设置为std::exception::exception()

After 50 mins of guessing I found out that problem was in length field. 经过50分钟的猜测,我发现问题出现在length领域。 The documentation doesn't say that but its default value has to be -1 as stated in source code 文档没有说明,但其默认值必须为-1,如源代码中所述

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

I intuitively assumed that if I set new_file_size to be more than zero it would ignore length . 我直观地假设如果我将new_file_size设置为大于零,则会忽略length

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM