summaryrefslogtreecommitdiff
path: root/src/mongo/util/assert_util.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-10-16 18:59:08 -0400
committerMathias Stearn <mathias@10gen.com>2017-11-02 14:25:21 -0400
commita0ebc55db521792632fb3ece87edafec327cc2a9 (patch)
treeb2098c89f241082a9c1a55ed69794eef210aa312 /src/mongo/util/assert_util.cpp
parent9f8696b5ba4c9310749c5c3f1ee082c5f663b5b0 (diff)
downloadmongo-a0ebc55db521792632fb3ece87edafec327cc2a9.tar.gz
SERVER-31622 Fix bad throws
Diffstat (limited to 'src/mongo/util/assert_util.cpp')
-rw-r--r--src/mongo/util/assert_util.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp
index b1433b0e3b4..bd1bc9f986a 100644
--- a/src/mongo/util/assert_util.cpp
+++ b/src/mongo/util/assert_util.cpp
@@ -55,6 +55,22 @@ using namespace std;
namespace mongo {
+namespace {
+
+/**
+ * This type is used for all exceptions that don't have a more specific type. It is defined locally
+ * in this file to prevent anyone from catching it specifically separately from AssertionException.
+ */
+class NonspecificAssertionException final : public AssertionException {
+public:
+ using AssertionException::AssertionException;
+
+private:
+ void defineOnlyInFinalSubclassToPreventSlicing() final {}
+};
+
+} // namespace
+
AssertionCount assertionCount;
AssertionCount::AssertionCount() : regular(0), warning(0), msg(0), user(0), rollovers(0) {}
@@ -113,14 +129,14 @@ NOINLINE_DECL void verifyFailed(const char* expr, const char* file, unsigned lin
logContext();
stringstream temp;
temp << "assertion " << file << ":" << line;
- AssertionException e(0, temp.str());
+
breakpoint();
#if defined(MONGO_CONFIG_DEBUG_BUILD)
// this is so we notice in buildbot
severe() << "\n\n***aborting after verify() failure as this is a debug/test build\n\n" << endl;
std::abort();
#endif
- throw e;
+ throw NonspecificAssertionException(ErrorCodes::UnknownError, temp.str());
}
NOINLINE_DECL void invariantFailed(const char* expr, const char* file, unsigned line) noexcept {
@@ -186,7 +202,7 @@ NOINLINE_DECL void uassertedWithLocation(int msgid,
assertionCount.condrollover(++assertionCount.user);
LOG(1) << "User Assertion: " << msgid << ":" << redact(msg) << ' ' << file << ' ' << dec << line
<< endl;
- throw AssertionException(msgid, msg);
+ throw NonspecificAssertionException(msgid, msg);
}
NOINLINE_DECL void msgassertedWithLocation(int msgid,
@@ -196,7 +212,7 @@ NOINLINE_DECL void msgassertedWithLocation(int msgid,
assertionCount.condrollover(++assertionCount.msg);
error() << "Assertion: " << msgid << ":" << redact(msg) << ' ' << file << ' ' << dec << line
<< endl;
- throw AssertionException(msgid, msg);
+ throw NonspecificAssertionException(msgid, msg);
}
std::string causedBy(StringData e) {