diff options
author | chegoryu <chegoryu@yandex-team.ru> | 2022-04-26 14:24:38 +0300 |
---|---|---|
committer | chegoryu <chegoryu@yandex-team.ru> | 2022-04-26 14:24:38 +0300 |
commit | 4513350c69deee250d0b12f40562bdf48868b171 (patch) | |
tree | 534b8e3fd269656d6131b7fd07c5bc1e51870209 | |
parent | d5542c891803641fb11f2edf0d71e6004a5e9c38 (diff) | |
download | ydb-4513350c69deee250d0b12f40562bdf48868b171.tar.gz |
IGNIETFERRO-1997 replace Y_VERIFY(exceptionPtr) with 'return "NO EXCEPTION"' in FormatCurrentException
ref:02c5a1e631a36a1f21b5b7678ecf4e245769dd9e
-rw-r--r-- | util/generic/yexception.cpp | 11 | ||||
-rw-r--r-- | util/generic/yexception_ut.cpp | 7 |
2 files changed, 13 insertions, 5 deletions
diff --git a/util/generic/yexception.cpp b/util/generic/yexception.cpp index cccf44ad50..780c98ede2 100644 --- a/util/generic/yexception.cpp +++ b/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 diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp index ae71a1ce22..80754d313e 100644 --- a/util/generic/yexception_ut.cpp +++ b/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) { |