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

Throwing in bsoncxx::document::element::get_*() if the element is invalid.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.6
    • Affects Version/s: None
    • Component/s: API
    • None

      Hello,

      Could bsoncxx::document::element::get_() functions - like get_oid(), get_double(), etc. -  throw a *bsoncxx::exception{error_code::k_unset_element} when the element is invalid ?
      Currently, a BSON_ASSERT() abort the program in that case.

      This would allow to do something like that :

      try {
      
        myOID          = documentView["_id"].get_oid().value;
        myIntegerValue = documentView["count"].get_int32().value;
      
      } catch (const std::exception& e) {
      
        if (e.code() == bsoncxx::error_code::k_unset_element) {
      
          throwIfFieldElementUnset(documentView, "_id");
          throwIfFieldElementUnset(documentView, "count");
      
        } else {
          
          throw;
        }
      }

       

      Also, it would be safer for case where the programmer wrongly use these methods on an invalid element : instead of aborting. exceptions would probably already be handled.

       

            Assignee:
            samantha.ritter@mongodb.com Samantha Ritter (Inactive)
            Reporter:
            adrian.blandin@sovo-tech.com Adrian B
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: