Skip to content

json::out_of_range exception matches against lot of others while testing #3352

@nandanvasudevan

Description

@nandanvasudevan

What is the issue you have?

I was trying out https://github.com/nlohmann/json and wanted to test the exception mechanism it had.
My initial attempt was to use CHECK_THROWS but that was really difficult since nlohmann::json::out_of_range is not easy to construct.
CHECK_THROWS_AS was what I was supposed to use and that worked fine.

Before figure that out I tried CHECK_THROWS with std::out_of_range and to my surprise that worked! The test also passed with std::bad_alloc.

I am not sure if this is to be expected since nlohmann::json::out_of_range is derived from std::exception.

Please describe the steps to reproduce the issue.

This Code snippet

Can you provide a small but working code example?

Minimal example here: https://github.com/nandanvasudevan/cpp_scratch_pad/tree/json_parsing

What is the expected behavior?

I expect the above tests to fail.
catchorg/Catch2#2371

And what is the actual behavior instead?

The tests pass.

Which compiler and operating system are you using?

  • Compiler: GCC v11
  • Operating system: Jammy Jellyfish (development branch)
  • Test framework: Catch2 v3 Preview 4

Which version of the library did you use?

  • latest release version 3.10.5
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

Compiles fine.

  • yes
  • no - please copy/paste the error message below

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions