From 1de80e8af4ae6ac2840d41efb2f960ee95035303 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 14 Mar 2017 21:31:36 +0100 Subject: [PATCH] :hammer: added user-defined exception #493 Replaced old std::invalid_argument exception by parse_error.111 to have unified exceptions in case of input stream errors. --- src/json.hpp | 2 +- src/json.hpp.re2c | 2 +- test/src/unit-regression.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 3fedc045..5a9399fd 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -11334,7 +11334,7 @@ basic_json_parser_74: // check if stream is still good if (m_stream->fail()) { - JSON_THROW(std::invalid_argument("stream error")); + JSON_THROW(parse_error(111, 0, "bad input stream")); } std::getline(*m_stream, m_line_buffer_tmp, '\n'); diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 7e7e16e3..e2dd777b 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -10367,7 +10367,7 @@ class basic_json // check if stream is still good if (m_stream->fail()) { - JSON_THROW(std::invalid_argument("stream error")); + JSON_THROW(parse_error(111, 0, "bad input stream")); } std::getline(*m_stream, m_line_buffer_tmp, '\n'); diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index ce984b0d..3f17a917 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -924,7 +924,8 @@ TEST_CASE("regression tests") l.m_stream->setstate(std::ios_base::failbit); - CHECK_THROWS_AS(l.fill_line_buffer(), std::invalid_argument); + CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error); + CHECK_THROWS_WITH(l.fill_line_buffer(), "[json.exception.parse_error.111] parse error: bad input stream"); } SECTION("setting badbit") @@ -938,7 +939,8 @@ TEST_CASE("regression tests") l.m_stream->setstate(std::ios_base::badbit); - CHECK_THROWS_AS(l.fill_line_buffer(), std::invalid_argument); + CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error); + CHECK_THROWS_WITH(l.fill_line_buffer(), "[json.exception.parse_error.111] parse error: bad input stream"); } }