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.