diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2015-04-03 11:33:28 -0400 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2015-04-03 13:47:40 -0400 |
commit | 78aa03b4eda2784ae67eba32d6b103166f1c57ad (patch) | |
tree | 0da01488fe8499ec28cb49d3aa61073c28c62f1e /src/mongo/util/assert_util.cpp | |
parent | 998cf155edc16019758d163e8f844c0986996bcf (diff) | |
download | mongo-78aa03b4eda2784ae67eba32d6b103166f1c57ad.tar.gz |
SERVER-17850 add utility to convert an exception to a Status
Diffstat (limited to 'src/mongo/util/assert_util.cpp')
-rw-r--r-- | src/mongo/util/assert_util.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index 99a594a85b5..17fd2f5d27f 100644 --- a/src/mongo/util/assert_util.cpp +++ b/src/mongo/util/assert_util.cpp @@ -46,6 +46,7 @@ using namespace std; #include "mongo/util/debugger.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" +#include "mongo/util/mongoutils/str.h" #include "mongo/util/quick_exit.h" #include "mongo/util/stacktrace.h" @@ -273,6 +274,22 @@ namespace mongo { #endif } + Status exceptionToStatus() { + try { + throw; + } catch (const DBException& ex) { + return ex.toStatus(); + } 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"); + } + } + string ExceptionInfo::toString() const { stringstream ss; ss << "exception: " << code << " " << msg; return ss.str(); } |