| 13 | // a limited subset of core libraries that are needed to implement NYT::TError. |
| 14 | |
| 15 | class TSimpleException |
| 16 | : public std::exception |
| 17 | { |
| 18 | public: |
| 19 | using TAttributes = THashMap< |
| 20 | TExceptionAttribute::TKey, |
| 21 | TExceptionAttribute::TValue>; |
| 22 | |
| 23 | template <class TValue> |
| 24 | static constexpr bool CNestable = requires (TSimpleException& ex, TValue&& operand) { |
| 25 | { ex <<= std::forward<TValue>(operand) } -> std::same_as<TSimpleException&>; |
| 26 | }; |
| 27 | |
| 28 | explicit TSimpleException(std::string message); |
| 29 | TSimpleException( |
| 30 | const std::exception& exception, |
| 31 | std::string message); |
| 32 | |
| 33 | const std::exception_ptr& GetInnerException() const; |
| 34 | const char* what() const noexcept override; |
| 35 | |
| 36 | const std::string& GetMessage() const; |
| 37 | |
| 38 | const TAttributes& GetAttributes() const &; |
| 39 | TAttributes&& GetAttributes() &&; |
| 40 | |
| 41 | TSimpleException& operator<<= (TExceptionAttribute&& attribute) &; |
| 42 | TSimpleException& operator<<= (std::vector<TExceptionAttribute>&& attributes) &; |
| 43 | TSimpleException& operator<<= (TAttributes&& attributes) &; |
| 44 | |
| 45 | TSimpleException& operator<<= (const TExceptionAttribute& attribute) &; |
| 46 | TSimpleException& operator<<= (const std::vector<TExceptionAttribute>& attributes) &; |
| 47 | TSimpleException& operator<<= (const TAttributes& attributes) &; |
| 48 | |
| 49 | // NB: clang is incapable of parsing such requirements (which refer back to the class) out-of-line. |
| 50 | // To keep this overload from winning in resolution |
| 51 | // when constraint actually fails, we define method right here. |
| 52 | template <class TValue> |
| 53 | requires CNestable<TValue> |
| 54 | TSimpleException&& operator<< (TValue&& value) && |
| 55 | { |
| 56 | return std::move(*this <<= std::forward<TValue>(value)); |
| 57 | } |
| 58 | |
| 59 | template <class TValue> |
| 60 | requires CNestable<TValue> |
| 61 | TSimpleException operator<< (TValue&& value) const & |
| 62 | { |
| 63 | return TSimpleException(*this) << std::forward<TValue>(value); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | const std::exception_ptr InnerException_; |
| 68 | const std::string Message_; |
| 69 | const std::string What_; |
| 70 | |
| 71 | TAttributes Attributes_; |
| 72 | }; |
no test coverage detected