diff options
Diffstat (limited to 'src/mongo/util/assert_util.cpp')
-rw-r--r-- | src/mongo/util/assert_util.cpp | 24 |
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) { |