Skip to content
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

Throw json schema validator exception by default #170

Open
Leon0402 opened this issue Sep 11, 2021 · 1 comment
Open

Throw json schema validator exception by default #170

Leon0402 opened this issue Sep 11, 2021 · 1 comment

Comments

@Leon0402
Copy link
Contributor

Leon0402 commented Sep 11, 2021

Hi,

I noticed that the library by default just throws std::invalid_argument here

throw std::invalid_argument(std::string("At ") + ptr.to_string() + " of " + instance.dump() + " - " + message + "\n");
.

I don't want to catch std::invalid_argument. I know I can provide my own error handler, but it looks identical to the default one except that it throws a subclass of std::invalid_argument.
So I wonder if the lib itself could not just do that by default?

A second thing I wondered:

virtual void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) = 0;

Couldn't this member function made const and therefore every argument of validate made const too? This would allow to pass RValue to validate().

So validate(j, MyHandler {});

@pboettch
Copy link
Owner

Thanks for these ideas.

I haven't spent a lot of time thinking about exception-customization. I like your idea. Please issue a PR with an according change (also because I wouldn't know how to do it correctly).

Regarding constness, if there is something which is not const, but should be const, go ahead and make a PR. Especially if it improves the overall usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants