diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-08-31 22:15:17 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-08-31 22:15:17 +0800 |
commit | 5035f18f44f675af2faa4019b6de14b3f3aab270 (patch) | |
tree | ca3d89608ea96b123723ffe8e323ebb45530aec7 /include | |
parent | a53fc98afc6cf3dbccde265d895e26346b6f537f (diff) | |
download | cru-5035f18f44f675af2faa4019b6de14b3f3aab270.tar.gz cru-5035f18f44f675af2faa4019b6de14b3f3aab270.tar.bz2 cru-5035f18f44f675af2faa4019b6de14b3f3aab270.zip |
Use utf8 message in cru::Exception.
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/base/Exception.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/include/cru/base/Exception.h b/include/cru/base/Exception.h index b299acc4..d102c263 100644 --- a/include/cru/base/Exception.h +++ b/include/cru/base/Exception.h @@ -10,27 +10,32 @@ namespace cru { #endif class CRU_BASE_API Exception : public std::exception { public: - explicit Exception(String message = {}, + explicit Exception(std::string message = "", + std::unique_ptr<std::exception> inner = nullptr); + explicit Exception(StringView message, std::unique_ptr<std::exception> inner = nullptr); ~Exception() override; public: - String GetMessage() const { return message_; } + [[deprecated("Use GetUtf8Message.")]] String GetMessage() const { + return String::FromUtf8(message_); + } + + std::string GetUtf8Message() const { return this->message_; } std::exception* GetInner() const noexcept { return inner_.get(); } const char* what() const noexcept override; protected: - void SetMessage(String message) { message_ = std::move(message); } + void SetMessage(StringView message) { message_ = message.ToUtf8(); } void AppendMessage(StringView additional_message); void AppendMessage(std::optional<StringView> additional_message); private: - String message_; - mutable std::string utf8_message_; + std::string message_; std::unique_ptr<std::exception> inner_; }; |