简体   繁体   中英

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 ?

My configuration

  • boost 1.51
  • Visual Studio 2012 on Windows 7
  • GCC 4.7 on Ubuntu

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.

In Ubuntu it creates empty file of given size but throws exception on 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".

In desperate attempt to find out what's wrong I output typeid(ex).name() which shows

N5boost16exception_detail10clone_implINS0_19error_info_injectorISt9exception

which according to Google means: 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 . The name of the function may be different on your system: use nm -po program | less nm -po program | less and search for a function containing 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() .

After 50 mins of guessing I found out that problem was in length field. The documentation doesn't say that but its default value has to be -1 as stated in source code

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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