123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "exception.h"
- #include <library/cpp/yt/assert/assert.h>
- namespace NYT {
- ////////////////////////////////////////////////////////////////////////////////
- namespace {
- template <class TRange>
- void AddAttributes(TSimpleException::TAttributes& attrs, TRange&& range)
- {
- for (auto&& [key, value] : range) {
- YT_VERIFY(attrs.emplace(std::move(key), std::move(value)).second);
- }
- }
- } // namespace
- ////////////////////////////////////////////////////////////////////////////////
- TSimpleException::TSimpleException(TString message)
- : Message_(std::move(message))
- , What_(Message_)
- { }
- TSimpleException::TSimpleException(
- const std::exception& exception,
- TString message)
- : InnerException_(std::current_exception())
- , Message_(std::move(message))
- , What_(Message_ + "\n" + exception.what())
- { }
- const std::exception_ptr& TSimpleException::GetInnerException() const
- {
- return InnerException_;
- }
- const char* TSimpleException::what() const noexcept
- {
- return What_.c_str();
- }
- const TString& TSimpleException::GetMessage() const
- {
- return Message_;
- }
- const TSimpleException::TAttributes& TSimpleException::GetAttributes() const &
- {
- return Attributes_;
- }
- TSimpleException::TAttributes&& TSimpleException::GetAttributes() &&
- {
- return std::move(Attributes_);
- }
- TSimpleException& TSimpleException::operator<<= (TExceptionAttribute&& attribute) &
- {
- YT_VERIFY(Attributes_.emplace(std::move(attribute.Key), std::move(attribute.Value)).second);
- return *this;
- }
- TSimpleException& TSimpleException::operator<<= (std::vector<TExceptionAttribute>&& attributes) &
- {
- AddAttributes(Attributes_, std::move(attributes));
- return *this;
- }
- TSimpleException& TSimpleException::operator<<= (TAttributes&& attributes) &
- {
- AddAttributes(Attributes_, std::move(attributes));
- return *this;
- }
- TSimpleException& TSimpleException::operator<<= (const TExceptionAttribute& attribute) &
- {
- YT_VERIFY(Attributes_.emplace(attribute.Key, attribute.Value).second);
- return *this;
- }
- TSimpleException& TSimpleException::operator<<= (const std::vector<TExceptionAttribute>& attributes) &
- {
- AddAttributes(Attributes_, attributes);
- return *this;
- }
- TSimpleException& TSimpleException::operator<<= (const TAttributes& attributes) &
- {
- AddAttributes(Attributes_, attributes);
- return *this;
- }
- ////////////////////////////////////////////////////////////////////////////////
- } // namespace NYT
|