C++ throwing std::out_of_range should return a string with the reason of the error

fabioang
2013-10-03
2013-10-03
  • fabioang
    fabioang
    2013-10-03

    Now

    const JSONNode & JSONNode::at(const json_string & name_t) const json_throws(std::out_of_range) {
        JSON_CHECK_INTERNAL();
        JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("at"));
        if (JSONNode ** res = internal -> at(name_t)){
           return *(*res);
        }
        JSON_FAIL(json_string(JSON_TEXT("at const could not find child by name: ")) + name_t);
        json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
    }
    

    Changed to:

    const JSONNode & JSONNode::at(const json_string & name_t) const json_throws(std::out_of_range) {
        JSON_CHECK_INTERNAL();
        JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("at"));
        if (JSONNode ** res = internal -> at(name_t)){
           return *(*res);
        }
        JSON_FAIL(json_string(JSON_TEXT("at const could not find child by name: ")) + name_t);
        json_throw(std::out_of_range(json_string(JSON_TEXT("at const could not find child by name: ")) + name_t));
    }