From 068c7acda9822b8b32edeba09de1567303517ac0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 5 Mar 2017 18:40:09 +0100 Subject: [PATCH] :hammer: added user-defined exceptions 301 --- src/json.hpp | 8 ++++---- src/json.hpp.re2c | 8 ++++---- test/src/unit-constructor1.cpp | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 59010a133..508dd805f 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -2223,8 +2223,8 @@ class basic_json value_t::array and @ref value_t::object are valid); when @a type_deduction is set to `true`, this parameter has no effect - @throw std::domain_error if @a type_deduction is `false`, @a manual_type - is `value_t::object`, but @a init contains an element which is not a pair + @throw type_error.301 if @a type_deduction is `false`, @a manual_type is + `value_t::object`, but @a init contains an element which is not a pair whose first element is a string; example: `"cannot create object from initializer list"` @@ -2264,7 +2264,7 @@ class basic_json // if object is wanted but impossible, throw an exception if (manual_type == value_t::object and not is_an_object) { - JSON_THROW(std::domain_error("cannot create object from initializer list")); + JSON_THROW(type_error(301, "cannot create object from initializer list")); } } @@ -2347,7 +2347,7 @@ class basic_json @return JSON object value - @throw std::domain_error if @a init is not a pair whose first elements are + @throw type_error.301 if @a init is not a pair whose first elements are strings; thrown by @ref basic_json(std::initializer_list, bool, value_t) diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index e87feb486..03d873af6 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2223,8 +2223,8 @@ class basic_json value_t::array and @ref value_t::object are valid); when @a type_deduction is set to `true`, this parameter has no effect - @throw std::domain_error if @a type_deduction is `false`, @a manual_type - is `value_t::object`, but @a init contains an element which is not a pair + @throw type_error.301 if @a type_deduction is `false`, @a manual_type is + `value_t::object`, but @a init contains an element which is not a pair whose first element is a string; example: `"cannot create object from initializer list"` @@ -2264,7 +2264,7 @@ class basic_json // if object is wanted but impossible, throw an exception if (manual_type == value_t::object and not is_an_object) { - JSON_THROW(std::domain_error("cannot create object from initializer list")); + JSON_THROW(type_error(301, "cannot create object from initializer list")); } } @@ -2347,7 +2347,7 @@ class basic_json @return JSON object value - @throw std::domain_error if @a init is not a pair whose first elements are + @throw type_error.301 if @a init is not a pair whose first elements are strings; thrown by @ref basic_json(std::initializer_list, bool, value_t) diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index d99855d83..e71c2c460 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -943,9 +943,9 @@ TEST_CASE("constructors") SECTION("object with error") { CHECK_THROWS_AS(json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), - std::logic_error); + json::type_error); CHECK_THROWS_WITH(json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), - "cannot create object from initializer list"); + "[json.exception.type_error.301] cannot create object from initializer list"); } SECTION("empty array") -- GitLab