From 5035f18f44f675af2faa4019b6de14b3f3aab270 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sun, 31 Aug 2025 22:15:17 +0800 Subject: Use utf8 message in cru::Exception. --- include/cru/base/Exception.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'include') 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 inner = nullptr); + explicit Exception(StringView message, std::unique_ptr 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 additional_message); private: - String message_; - mutable std::string utf8_message_; + std::string message_; std::unique_ptr inner_; }; -- cgit v1.2.3