| 462 | } |
| 463 | |
| 464 | PreformattedMessage getCurrentExceptionMessageAndPattern( |
| 465 | bool with_stacktrace, |
| 466 | bool check_embedded_stacktrace /*= false*/, |
| 467 | bool with_extra_info /*= true*/, |
| 468 | bool with_version /*= true*/) |
| 469 | { |
| 470 | /// Explicitly block MEMORY_LIMIT_EXCEEDED |
| 471 | LockMemoryExceptionInThread lock_memory_tracker(VariableContext::Global); |
| 472 | |
| 473 | WriteBufferFromOwnString stream; |
| 474 | std::string_view message_format_string; |
| 475 | std::vector<std::string> message_format_string_args; |
| 476 | |
| 477 | try |
| 478 | { |
| 479 | throw; |
| 480 | } |
| 481 | catch (const Exception & e) |
| 482 | { |
| 483 | stream << getExceptionMessage(e, with_stacktrace, check_embedded_stacktrace) |
| 484 | << (with_extra_info ? getExtraExceptionInfo(e) : ""); |
| 485 | if (with_version) |
| 486 | stream << " (version " << VERSION_STRING << VERSION_OFFICIAL << ")"; |
| 487 | message_format_string = e.tryGetMessageFormatString(); |
| 488 | message_format_string_args = e.getMessageFormatStringArgs(); |
| 489 | } |
| 490 | catch (const Poco::Exception & e) |
| 491 | { |
| 492 | try |
| 493 | { |
| 494 | stream << "Poco::Exception. Code: " << ErrorCodes::POCO_EXCEPTION << ", e.code() = " << e.code() |
| 495 | << ", " << e.displayText() |
| 496 | << (with_stacktrace ? formatStackTraceSection(getExceptionStackTraceString(e)) : "") |
| 497 | << (with_extra_info ? getExtraExceptionInfo(e) : ""); |
| 498 | if (with_version) |
| 499 | stream << " (version " << VERSION_STRING << VERSION_OFFICIAL << ")"; |
| 500 | } |
| 501 | catch (...) {} // NOLINT(bugprone-empty-catch) Ok: best-effort exception formatting, must not throw |
| 502 | } |
| 503 | catch (const std::exception & e) |
| 504 | { |
| 505 | try |
| 506 | { |
| 507 | int status = 0; |
| 508 | auto name = demangle(typeid(e).name(), status); |
| 509 | |
| 510 | if (status) |
| 511 | name += " (demangling status: " + toString(status) + ")"; |
| 512 | |
| 513 | stream << "std::exception. Code: " << ErrorCodes::STD_EXCEPTION << ", type: " << name << ", e.what() = " << e.what() |
| 514 | << (with_stacktrace ? formatStackTraceSection(getExceptionStackTraceString(e)) : "") |
| 515 | << (with_extra_info ? getExtraExceptionInfo(e) : ""); |
| 516 | if (with_version) |
| 517 | stream << " (version " << VERSION_STRING << VERSION_OFFICIAL << ")"; |
| 518 | } |
| 519 | catch (...) {} // NOLINT(bugprone-empty-catch) Ok: best-effort exception formatting, must not throw |
| 520 | |
| 521 | if (debug_or_sanitizer_build || abort_on_logical_error.load(std::memory_order_relaxed)) |
no test coverage detected