Skip to content

Parse throw std::ios_base::failure exception when failbit set to true #714

Description

@dPavelDev

In brief:

std::ifstream is;
is.exceptions(
      is.exceptions() 
    | std::ios_base::failbit 
    | std::ios_base::badbit
); // handle different exceptions as 'file not found', 'permission denied'

try { 
    is.open("my_valid_file.json");
    const auto &jsonFile = nlohmann::json::parse(is); // (*)
    // ...
catch (const std::ios_base::failure &e) {
    std::cerr << e.code().message() << std::endl;
}

The line (*) produce std::ios_base::failure exception when parse function reaches end of stream even if json document is valid. Without std::ios_base::failbit function works OK.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions