Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-862

The element and array type operator[] function should not throw

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.1
    • Affects Version/s: 3.0.0
    • Component/s: API
    • None

      There is an awkward inconsistency in the operator[] interface for bsoncxx::document::element and bsoncxx::document::array.

      If element::operator[] or array::operator[] is called and a matching element is not found, we return an invalid element.

      Similarly, if you call element::operator[] (either overload) and a matching element is not found, we also return an invalid element, as long as the type of the current element is document or array.

      However, if you call element::operator[] (either overload) on something that is neither a document nor an array, an exception is thrown.

      This means that a statement like:

      foo[a][b][c][d]

      May either throw or return an invalid element, depending on the shape of the document foo.

      This is pretty hard to handle. We should make it either throw, always, on a missing element, or degrade to an invalid element, always.

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: