[SERVER-7889] Handling data type errors with UserException in MongoDB with the C++ driver Created: 10/Dec/12  Updated: 11/Jul/16  Resolved: 09/Jul/13

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 2.2.0
Fix Version/s: 2.5.1

Type: Question Priority: Minor - P4
Reporter: George Thompson Assignee: Matt Kangas
Resolution: Done Votes: 0
Labels: pull-request
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 64 SP1 MongoDB 2.2.0 C++ driver MSVS 2010


Issue Links:
Related
related to DOCS-907 C++ driver doc says we throw wrong er... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

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!



 Comments   
Comment by Matt Kangas [ 09/Jul/13 ]

Merged in 0e4a3a0c8

Comment by auto [ 09/Jul/13 ]

Author:

{u'username': u'daveh86', u'name': u'daveh86', u'email': u'howsdav@gmail.com'}

Message: SERVER-7889 change comments to fix api docs

Change the documented exception thrown by all instances of chk() from
UserException to MsgAssertionException

Signed-off-by: Matt Kangas <matt.kangas@10gen.com>
Branch: master
https://github.com/mongodb/mongo/commit/0e4a3a0c8439de066a09c3d17f1c23be85b49273

Comment by Daniel Pasette (Inactive) [ 19/Dec/12 ]

The assertion type was changed but not the code's documentation with this commit: https://github.com/mongodb/mongo/commit/f91b04bd34fbbcbdfb3ca0ed06d530068c9205d6

Just need to match them up.

Comment by David Hows [ 19/Dec/12 ]

Hi Gegorge,

Your understanding is correct, it throws a MsgAssertionException.

I have raised DOCS-907 to have this one addressed.

Cheers,

David

Generated at Thu Feb 08 03:15:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.