Subject: [Boost-bugs] [Boost C++ Libraries] #8465: ptree get_child should not throw an exception on empty sets
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-04-19 18:45:37
#8465: ptree get_child should not throw an exception on empty sets
-----------------------------------------------------+----------------------
Reporter: Dale Stansberry <stansberrydv@â¦> | Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.53.0
Severity: Problem | Keywords:
-----------------------------------------------------+----------------------
I feel there is an design issue with the ptree::get_child() method related
to the choice of throwing an exception when reading an empty source. The
typical use of get_child() employs of a for loop (or BOOST_FOREACH) which
one expects to exhibit the standard behaviour of a container iterator:
loop over contained items until finished, and if there are no items, then
do nothing. Throwing an exception if no child exists does not conform to
this expected behaviour (and was poorly documented as well...) and it also
does not really comply with the concept of an exceptional condition (for
cases where empty/optional sources are expected). I think it would be
acceptable to throw an exception if the data content of the source was
malformed, but an empty set could simply indicate optional data that is
not present.
I'm a fairly new user of Boost, so if there is an alternative method for
iterating over child trees in a more iterator-compliant manner, I
apologize for the disruption (although if this is the case, the
documentation probably needs to be updated).
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8465> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC