Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-18050 catch boost::exception in exceptionToStatus

commit 71e1d4f8d5f515d6fc272faa20f81255e5766dc9 1 parent 1437d84
@amidvidy amidvidy authored
Showing with 35 additions and 12 deletions.
  1. +11 −4 src/mongo/base/status_test.cpp
  2. +24 −8 src/mongo/util/assert_util.cpp
View
15 src/mongo/base/status_test.cpp
@@ -26,9 +26,12 @@
* then also delete it in the license file.
*/
+#include <exception>
#include <stdexcept>
#include <string>
+#include <boost/exception/exception.hpp>
+
#include "mongo/base/status.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
@@ -236,17 +239,21 @@ namespace {
ASSERT_TRUE(fromStdExcept.reason().find(reason) != std::string::npos);
ASSERT_EQUALS(fromStdExcept.code(), ErrorCodes::UnknownError);
- Status fromNonExcept = []() {
+ class bar : public boost::exception {};
+
+ Status fromBoostExcept = [=]() {
try {
- throw 4;
+ throw bar();
}
catch (...) {
return exceptionToStatus();
}
}();
- ASSERT_NOT_OK(fromNonExcept);
- ASSERT_EQUALS(fromNonExcept, ErrorCodes::UnknownError);
+ ASSERT_NOT_OK(fromBoostExcept);
+ ASSERT_EQUALS(fromBoostExcept, ErrorCodes::UnknownError);
+ // Reason should include that it was a boost::exception
+ ASSERT_TRUE(fromBoostExcept.reason().find("boost::exception") != std::string::npos);
}
} // unnamed namespace
View
32 src/mongo/util/assert_util.cpp
@@ -40,6 +40,10 @@ using namespace std;
#include <sys/file.h>
#endif
+#include <boost/exception/diagnostic_information.hpp>
+#include <boost/exception/exception.hpp>
+#include <exception>
+
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
#include "mongo/util/debug_util.h"
@@ -277,16 +281,28 @@ namespace mongo {
Status exceptionToStatus() {
try {
throw;
- } catch (const DBException& ex) {
+ }
+ catch (const DBException& ex) {
return ex.toStatus();
- } catch (const std::exception& ex) {
+ }
+ catch (const std::exception& ex) {
return Status(ErrorCodes::UnknownError,
- mongoutils::str::stream() << "Caught exception of type "
- << demangleName(typeid(ex))
- << ": "
- << ex.what());
- } catch (...) {
- return Status(ErrorCodes::UnknownError, "Caught unknown exception");
+ str::stream() << "Caught std::exception of type "
+ << demangleName(typeid(ex))
+ << ": "
+ << ex.what());
+ }
+ catch (const boost::exception& ex) {
+ return Status(ErrorCodes::UnknownError,
+ str::stream() << "Caught boost::exception of type "
+ << demangleName(typeid(ex))
+ << ": "
+ << boost::diagnostic_information(ex));
+
+ }
+ catch (...) {
+ severe() << "Caught unknown exception in exceptionToStatus()";
+ std::terminate();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.