哪些异常会导致mapped_file_source抛出

What exceptions does boost mapped_file_source throw?

本文关键字:file source 抛出 mapped 异常      更新时间:2023-10-16

Boost mapped_file_source似乎在例如找不到文件的情况下抛出异常。它到底抛出了哪些异常类?文件中似乎没有写,除非我遗漏了什么。

编辑:测试用例:

#include <boost/iostreams/device/mapped_file.hpp>
int main(int argc, char** argv) {
    boost::iostreams::mapped_file_source file;
    file.open(argv[1]);
    return 0;
}

如果映射失败,代码

mapped_handle_ = 
        ::CreateFileMappingA( 
            handle_, 
            NULL,
            protect,
            0, 
            0, 
            NULL );
    if (mapped_handle_ == NULL)
        cleanup_and_throw("failed create mapping");

最终会抛出

boost::iostreams::detail::throw_system_failure(msg);

即CCD_ 1的子类。在这种情况下,它应该是std::ios::failure:

BOOST_IOSTREAMS_FAILURE

扩展到std::ios_base::failure(如果可用),并扩展到合适的std:的派生类:否则为异常。

参考:http://www.boost.org/doc/libs/1_41_0/libs/iostreams/src/mapped_file.cpp