Skip to content

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

Closed

Description

@adityamarella

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) {
   ...
}

Activity

  1. gregmarr commented on Sep 27, 2017

    @gregmarr
    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.

  2. nlohmann commented on Sep 29, 2017

    @nlohmann
    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.

  3. self-assigned this
    on Sep 29, 2017
  4. nlohmann commented on Oct 27, 2017

    @nlohmann
    Owner

    Closing this. Exceptions will be documented in 3.0.0.

  5. added this to the Release 3.0.0 milestone on Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions