diff options
author | jansenin <jansenin@yandex-team.com> | 2023-07-31 18:31:59 +0300 |
---|---|---|
committer | jansenin <jansenin@yandex-team.com> | 2023-07-31 18:31:59 +0300 |
commit | feac8eca6ce672915a1c91f4942ef59c5994e215 (patch) | |
tree | 63aeb507fcf4fe0c766babc315cf1772bec59f0e /library/cpp/yaml/fyamlcpp/fyamlcpp.h | |
parent | dec41c40e51aa407edef81a3c566a5a15780fc49 (diff) | |
download | ydb-feac8eca6ce672915a1c91f4942ef59c5994e215.tar.gz |
add exception with related exceptions
Diffstat (limited to 'library/cpp/yaml/fyamlcpp/fyamlcpp.h')
-rw-r--r-- | library/cpp/yaml/fyamlcpp/fyamlcpp.h | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/library/cpp/yaml/fyamlcpp/fyamlcpp.h b/library/cpp/yaml/fyamlcpp/fyamlcpp.h index ca532563494..a6bdf569274 100644 --- a/library/cpp/yaml/fyamlcpp/fyamlcpp.h +++ b/library/cpp/yaml/fyamlcpp/fyamlcpp.h @@ -5,6 +5,7 @@ #include <util/system/yassert.h> #include <util/stream/str.h> #include <util/generic/hash_set.h> +#include <util/generic/vector.h> #include <memory> #include <optional> @@ -25,7 +26,42 @@ struct TStringPtrHashT { } }; -struct TFyamlEx : public yexception {}; +// do TFyaml(str) instead of TFyaml() << str; +class TFyamlEx : public yexception { +public: + TFyamlEx() {} + + TFyamlEx(TString error) : Errors_({error}) {} + + TFyamlEx(std::initializer_list<TString> errors) : Errors_(errors) {} + + const TVector<TString>& Errors() { + return Errors_; + } + + const char* what() const noexcept override { + What_ = TString(yexception::what()); + for (auto& err : Errors_) { + What_.push_back('\n'); + What_.append(err); + } + + return What_.c_str(); + } + + TFyamlEx& AddError(TString error) { + Errors_.push_back(error); + return *this; + } + + TStringBuf AsStrBuf() const { + return what(); + } + +private: + TVector<TString> Errors_; + mutable TString What_; +}; enum class ENodeType { Scalar, @@ -65,6 +101,8 @@ private: std::unique_ptr<T> Data_ = nullptr; }; +void ThrowAllExceptionsIfAny(fy_diag* diag); + void RethrowError(fy_diag* diag); void RethrowOnError(bool isError, fy_node* node); |