Browse Source

IGNIETFERRO-1997 replace Y_VERIFY(exceptionPtr) with 'return "NO EXCEPTION"' in FormatCurrentException

ref:02c5a1e631a36a1f21b5b7678ecf4e245769dd9e
chegoryu 2 years ago
parent
commit
4513350c69
2 changed files with 13 additions and 5 deletions
  1. 6 5
      util/generic/yexception.cpp
  2. 7 0
      util/generic/yexception_ut.cpp

+ 6 - 5
util/generic/yexception.cpp

@@ -59,11 +59,12 @@ Y_DECLARE_UNUSED static void FormatBackTraceTo(IOutputStream& out, const TBackTr
 
 void FormatCurrentExceptionTo(IOutputStream& out) {
     auto exceptionPtr = std::current_exception();
-    /*
-     * The lack of current exception indicates a logical bug in the client code.
-     * Do not make any attempts to workaround it, just panic and abort.
-     */
-    Y_VERIFY(exceptionPtr != nullptr, "there is no current exception");
+
+    if (Y_UNLIKELY(!exceptionPtr)) {
+        out << "(NO EXCEPTION)\n";
+        return;
+    }
+
 #ifdef _YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
     TBackTrace backtrace = TBackTrace::FromCurrentException();
 #endif

+ 7 - 0
util/generic/yexception_ut.cpp

@@ -51,6 +51,9 @@ class TExceptionTest: public TTestBase {
     UNIT_TEST(TestEnsureWithBackTrace2)
 #ifdef _YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
     UNIT_TEST(TestFormatCurrentException)
+#endif
+    UNIT_TEST(TestFormatCurrentExceptionWithNoException)
+#ifdef _YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
     UNIT_TEST(TestFormatCurrentExceptionWithInvalidBacktraceFormatter)
 #endif
     UNIT_TEST(TestRethrowAppend)
@@ -148,6 +151,10 @@ private:
     }
 #endif
 
+    void TestFormatCurrentExceptionWithNoException() {
+        UNIT_ASSERT_VALUES_EQUAL(FormatCurrentException(), "(NO EXCEPTION)\n");
+    }
+
 #ifdef _YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
     void TestFormatCurrentExceptionWithInvalidBacktraceFormatter() {
         auto invalidFormatter = [](IOutputStream*, void* const*, size_t) {