We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
CHECK_THROWS
nlohmann::json::out_of_range
CHECK_THROWS_AS
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.
std::out_of_range
std::bad_alloc
I am not sure if this is to be expected since nlohmann::json::out_of_range is derived from std::exception.
This Code snippet
Code snippet
Minimal example here: https://github.com/nandanvasudevan/cpp_scratch_pad/tree/json_parsing
I expect the above tests to fail. catchorg/Catch2#2371
The tests pass.
develop
Compiles fine.
The text was updated successfully, but these errors were encountered:
By using just CHECK_THROWS, you are verifying that this expression throws:
jsonParsed_full.at("Nonexistent"), std::out_of_range("")
and since it does throw, the check passes. This is not a bug either in this library or in Catch2.
Sorry, something went wrong.
It does not throw std::out_of_range or std::bad_alloc.
I understand your point. I guess I am supposed to use CHECK_THROWS_AS if I need to verify the type of the exception.
See catchorg/Catch2#2371 (comment).
No branches or pull requests
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 sincenlohmann::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
withstd::out_of_range
and to my surprise that worked! The test also passed withstd::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?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
Compiles fine.
The text was updated successfully, but these errors were encountered: