diff options
author | Konstantin Khlebnikov <khlebnikov@tracto.ai> | 2025-02-16 12:50:19 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2025-02-16 13:13:15 +0300 |
commit | 7a3958c3c6de324baab9dba4bd4eb808c1b839a6 (patch) | |
tree | 4b0532c216b5ab8928fb75a329c602b6d088ad37 | |
parent | 802da2736bf00631aa408e495b80d6e125f10a9f (diff) | |
download | ydb-7a3958c3c6de324baab9dba4bd4eb808c1b839a6.tar.gz |
yt/error: optimize constructing TError from TErrorException
Here we can avoid dynamic cast and exception hazard.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@tracto.ai>
---
Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1070
commit_hash:e0709e1fe0f2109792b20b850e0e11a6e96f846a
-rw-r--r-- | library/cpp/yt/error/error-inl.h | 5 | ||||
-rw-r--r-- | library/cpp/yt/error/error.cpp | 6 | ||||
-rw-r--r-- | library/cpp/yt/error/error.h | 7 |
3 files changed, 18 insertions, 0 deletions
diff --git a/library/cpp/yt/error/error-inl.h b/library/cpp/yt/error/error-inl.h index c1ba73fbcf..f82b8eb20d 100644 --- a/library/cpp/yt/error/error-inl.h +++ b/library/cpp/yt/error/error-inl.h @@ -313,6 +313,11 @@ TErrorOr<T>::TErrorOr(TErrorOr<U>&& other) noexcept } template <class T> +TErrorOr<T>::TErrorOr(const TErrorException& errorEx) noexcept + : TError(errorEx) +{ } + +template <class T> TErrorOr<T>::TErrorOr(const std::exception& ex) : TError(ex) { } diff --git a/library/cpp/yt/error/error.cpp b/library/cpp/yt/error/error.cpp index 866c76eec8..4790fbf606 100644 --- a/library/cpp/yt/error/error.cpp +++ b/library/cpp/yt/error/error.cpp @@ -242,6 +242,12 @@ TError::TErrorOr(TError&& other) noexcept : Impl_(std::move(other.Impl_)) { } +TError::TErrorOr(const TErrorException& errorEx) noexcept +{ + *this = errorEx.Error(); + // NB: TErrorException verifies that error not IsOK at throwing end. +} + TError::TErrorOr(const std::exception& ex) { if (auto simpleException = dynamic_cast<const TSimpleException*>(&ex)) { diff --git a/library/cpp/yt/error/error.h b/library/cpp/yt/error/error.h index 3def2c4b50..beb097afe2 100644 --- a/library/cpp/yt/error/error.h +++ b/library/cpp/yt/error/error.h @@ -56,6 +56,9 @@ void FormatValue(TStringBuilderBase* builder, TErrorCode code, TStringBuf spec); //////////////////////////////////////////////////////////////////////////////// +// Forward declaration. +class TErrorException; + template <class TValue> concept CErrorNestable = requires (TError& error, TValue&& operand) { @@ -72,6 +75,8 @@ public: TErrorOr(const TError& other); TErrorOr(TError&& other) noexcept; + TErrorOr(const TErrorException& errorEx) noexcept; + TErrorOr(const std::exception& ex); struct TDisableFormat @@ -365,6 +370,8 @@ public: TErrorOr(const TError& other); TErrorOr(TError&& other) noexcept; + TErrorOr(const TErrorException& errorEx) noexcept; + TErrorOr(const std::exception& ex); template <class U> |