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

Proposal: out_of_range should be a subclass of std::out_of_range #756

Closed
adityamarella opened this issue Sep 27, 2017 · 3 comments
Closed
Assignees
Milestone

Comments

@adityamarella
Copy link

adityamarella commented Sep 27, 2017

class out_of_range : public exception

Is there any reason not to inherit out_of_range exception from std::out_of_range?

The current release version v2.1.1 is throwing std::out_of_range but the latest on develop throws custom out_of_range exception which could cause backward compatibility issues.

My code below was working with v2.1.1 release version, stopped working when I moved to the latest on develop

try {
    json.at("xxx")
} catch(std::out_of_range &e) {
   ...
}
@gregmarr
Copy link
Contributor

The exception types thrown in V3 are different than in V2 and will require updates. That's why they're in a different major version.

[nlohmann::json::exception] is an extension of std::exception objects with a member @A id for exception ids. It is used as the base class for all exceptions thrown by the @ref basic_json class. This class can hence be used as "wildcard" to catch exceptions.

@nlohmann
Copy link
Owner

As @gregmarr described correctly, we wanted to have an exception base class so users can easily catch all library-related exceptions. As these changes break the API, we add them in the upcoming 3.0.0 release. I shall mention these changes in the release notes so it is clear what needs to be changed in client code.

@nlohmann nlohmann self-assigned this Sep 29, 2017
@nlohmann
Copy link
Owner

Closing this. Exceptions will be documented in 3.0.0.

@nlohmann nlohmann added this to the Release 3.0.0 milestone Oct 27, 2017
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

3 participants