@@ -21,7 +21,8 @@ json::object::object(all_values data) {
2121 else if (data.index () == 6 )
2222 *this = std::get<std::map<std::string, object>>(data);
2323 else
24- throw std::runtime_error (" Invalid data type passed!" );
24+ logger::error (" Invalid data type passed" ,
25+ " json::object::object(all_values data)" );
2526 return ;
2627}
2728json::object::~object () { return ; }
@@ -91,18 +92,23 @@ json::object &json::object::operator[](const size_t index) {
9192 this ->assertIsArray ();
9293
9394 if (index >= this ->_array .size ()) {
94- throw std::out_of_range (" Index out of range" );
95+ logger::error (" Index out of range" ,
96+ " json::object &json::object::operator[](const size_t index)" );
9597 }
9698
9799 return this ->_array [index];
98100}
99101const json::object &json::object::operator [](const size_t index) const {
100102 if (!this ->_type .get () == type::array) {
101- throw std::runtime_error (" This object is not an array" );
103+ logger::error (" This object is not an array" ,
104+ " const json::object &json::object::operator[](const size_t "
105+ " index) const" );
102106 }
103107
104108 if (index >= this ->_array .size ()) {
105- throw std::out_of_range (" Index out of range" );
109+ logger::error (" Index out of range" ,
110+ " const json::object &json::object::operator[](const size_t "
111+ " index) const" );
106112 }
107113
108114 return this ->_array .at (index);
@@ -126,15 +132,19 @@ void json::object::push_back(object data) {
126132json::object &json::object::operator [](const std::string &key) {
127133
128134 if (!this ->_type .get () == type::map) {
129- throw std::runtime_error (" This object is not an object" );
135+ logger::error (
136+ " This object is not an object" ,
137+ " json::object &json::object::operator[](const std::string &key)" );
130138 }
131139
132140 this ->_type .set (type::map);
133141 return this ->_map [key];
134142}
135143const json::object &json::object::operator [](const std::string &key) const {
136144 if (this ->_type .get () != type::map) {
137- throw std::runtime_error (" This object is not an object" );
145+ logger::error (" This object is not an object" ,
146+ " const json::object &json::object::operator[](const "
147+ " std::string &key) const" );
138148 }
139149
140150 return this ->_map .at (key);
@@ -155,7 +165,8 @@ size_t json::object::size() {
155165 } else if (this ->_type .get () == type::map) {
156166 return this ->_map .size ();
157167 } else {
158- throw std::runtime_error (" Cannot get size of non-[array, map] objects" );
168+ logger::error (" Cannot get size of non-[array, map] objects" ,
169+ " size_t json::object::size()" );
159170 }
160171 return -1 ;
161172}
@@ -165,7 +176,8 @@ void json::object::clear() {
165176 } else if (this ->_type .get () == type::map) {
166177 this ->_map .clear ();
167178 } else {
168- throw std::runtime_error (" Cannot clear non-[array, map] objects" );
179+ logger::error (" Cannot clear non-[array, map] objects" ,
180+ " void json::object::clear()" );
169181 }
170182 return ;
171183}
@@ -182,7 +194,8 @@ void json::object::reset() {
182194void json::object::dump (std::string path, size_t indent) {
183195 std::ofstream jsonFile (path);
184196 if (!jsonFile.is_open ()) {
185- std::runtime_error (" Unable to open " + path);
197+ logger::error (" Unable to open " + path,
198+ " void json::object::dump(std::string path, size_t indent)" );
186199 }
187200
188201 std::string stringified = this ->dumps (indent);
@@ -280,7 +293,8 @@ void json::object::setArrayIfUndefined() {
280293void json::object::assertIsArray () {
281294 this ->setArrayIfUndefined ();
282295 if (this ->_type .get () != type::array) {
283- throw std::runtime_error (" This object is not an array" );
296+ logger::error (" This object is not an array" ,
297+ " void json::object::assertIsArray()" );
284298 }
285299}
286300
@@ -299,7 +313,8 @@ void json::object::setMapIfUndefined() {
299313void json::object::assertIsMap () {
300314 this ->setMapIfUndefined ();
301315 if (!this ->_type .get () == type::map) {
302- throw std::runtime_error (" This object is not an object" );
316+ logger::error (" This object is not an object" ,
317+ " void json::object::assertIsMap()" );
303318 }
304319}
305320
0 commit comments