-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
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
jPtr operation does not throw #1569
Comments
Can you provide a working sample that this error could be reproduced? Also, in addition to |
of course, I will try your suggestion here is my sample
|
There was a typo in the sample code. I've cleaned up a bit: #include "json.hpp"
#include <iostream>
using namespace std;
using namespace nlohmann;
void check()
{
nlohmann::json val;
json::json_pointer jsonPtr("/services/2/serviceName");
try
{
cout << "Checking..." << endl;
val = (std::string)val.at(jsonPtr);
cout << "no exception." << endl;
}
catch (json::parse_error& e)
{
val = 0;
cout << "thrown parse_error: " << e.what() << endl;
}
catch (json::out_of_range& e)
{
val = 0;
cout << "thrown out_of_range: " << e.what() << endl;
}
catch (std::exception& e)
{
val = 0;
cout << "thrown unknown exception: " << e.what() << endl;
}
}
int main(void)
{
check();
cout << "Done." << endl;
return 0;
} This outputs
which is expected (tested on version 3.6.1). |
By the way, I try something like that; what if wrong path was came from like "services" (it should be "services/2/serviceName"). I know it is wrong request but I assume that client side sent it. json::json_pointer jsonPtr("/services"); Then, I tried to catch it with json::exception and it works. Thanks a lot. |
When I use jptr like below( it is a bad request), I can't catch any throw. Is there any problem on my operation or Is this a bug?
Thanks a lot
The text was updated successfully, but these errors were encountered: