Skip to content

Commit 5115fa7

Browse files
committed
CXX-498 make OperationException inherit from DBException
1 parent faf0147 commit 5115fa7

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

src/mongo/client/exceptions.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ namespace mongo {
2222
}
2323

2424
OperationException::OperationException(const BSONObj& errorObj)
25-
: _lastError(errorObj)
26-
, _errorString(std::string(kName) + ": " + errorObj.toString())
25+
: DBException(std::string(kName) + ": " + errorObj.toString(), 0)
26+
, _lastError(errorObj)
2727
{}
2828

2929
OperationException::~OperationException() throw() {
3030
}
3131

32-
const char* OperationException::what() const throw() {
33-
return _errorString.c_str();
34-
}
35-
3632
} // namespace mongo

src/mongo/client/exceptions.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,21 @@
1919
#include <string>
2020

2121
#include "mongo/db/jsobj.h"
22+
#include "mongo/util/assert_util.h"
2223

2324
namespace mongo {
2425

2526
/**
2627
* General runtime exception generated by the MongoDB client driver.
2728
*/
28-
class MONGO_CLIENT_API OperationException : public std::exception {
29+
class MONGO_CLIENT_API OperationException : public DBException {
2930
public:
3031
/** Takes a BSONObj that is the result of the "getlasterror" command */
3132
OperationException(const BSONObj& errorObj);
3233

3334
/** Required due to BSONObj member desctructor not specifying throw() */
3435
virtual ~OperationException() throw();
3536

36-
/** The string version of the getlasterror result passed to constructor */
37-
virtual const char* what() const throw();
38-
3937
/** Get the last_error object representing the operation exception */
4038
const BSONObj& obj() const { return _lastError; }
4139

src/mongo/integration/replica_set/basic.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace {
5454
try {
5555
conn->insert(TEST_NS, BSON("x" << 2), 0, &WriteConcern::acknowledged);
5656
break;
57-
} catch (DBException&) {
57+
} catch (const DBException&) {
5858
mongo::sleepsecs(1);
5959
}
6060
}
@@ -69,10 +69,9 @@ namespace {
6969
conn->insert(TEST_NS, BSON("x" << 2), 0, &wcAll);
7070
break;
7171

72-
} catch (OperationException&) {
73-
// try again
74-
} catch (std::exception&) {
72+
} catch (const DBException&) {
7573
// try again
74+
mongo::sleepsecs(1);
7675
}
7776
}
7877
}

src/mongo/integration/replica_set/read_preference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace {
164164
try {
165165
replset_conn->findOne(TEST_NS, Query().readPref(ReadPreference_SecondaryOnly, BSONArray()));
166166
break;
167-
} catch (DBException& ex) {
167+
} catch (const DBException& ex) {
168168
std::cout << ex.what() <<std::endl;
169169
mongo::sleepsecs(1);
170170
}

0 commit comments

Comments
 (0)