Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7889

Handling data type errors with UserException in MongoDB with the C++ driver

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.1
    • Affects Version/s: 2.2.0
    • Component/s: Internal Client
    • Environment:
      Windows 7 64 SP1 MongoDB 2.2.0 C++ driver MSVS 2010
    • Fully Compatible

      According to:

      http://api.mongodb.org/cplusplus/2.2.0/classmongo_1_1_b_s_o_n_element.html#a692f3eecb505eae2181eb938b7680fbe

      Double() (and like functions) should "throw a UserException if the element is not of the required type."

      My code:

      {{ BSONObj a_document = BSON("a_string"<<"A string");

      try

      { a_document["a_string"].Double(); }

      catch(mongo::UserException ue)

      { cout << ue.toString() << endl; }

      }}
      But it doesn't get caught. Instead it asserts:

      {{Sun Dec 09 16:04:28 Assertion: 13111:wrong type for field (a_string) 2 != 1
      Sun Dec 09 16:04:28 dev: lastError==0 won't report:wrong type for field (a_string) 2 != 1}}

      My reading of bsonelement.h indicates it is throwing a MsgAssertionException – see line 472.

      Is the documentation or my understanding incorrect?

      Thanks!

            Assignee:
            matt.kangas Matt Kangas
            Reporter:
            therefore George Thompson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: