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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 3.6.6
    • None
    • API
    • None

    Description

      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.

       

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: