diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-04 22:51:27 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-04 22:51:27 +0800 |
commit | fdddc7f4a8884a8481dc71c0f34b8775659ba236 (patch) | |
tree | 7b43bc30a7666f4dc2a87e7999a9f26d911dbe66 /src/base/Exception.cpp | |
parent | 2ac35f7b67eac709cdae7981880f7d117f9a9d75 (diff) | |
download | cru-fdddc7f4a8884a8481dc71c0f34b8775659ba236.tar.gz cru-fdddc7f4a8884a8481dc71c0f34b8775659ba236.tar.bz2 cru-fdddc7f4a8884a8481dc71c0f34b8775659ba236.zip |
UnixFileDescriptor Read and ErrnoException std::string.
Diffstat (limited to 'src/base/Exception.cpp')
-rw-r--r-- | src/base/Exception.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/base/Exception.cpp b/src/base/Exception.cpp index 1e3813a9..2bf66fc6 100644 --- a/src/base/Exception.cpp +++ b/src/base/Exception.cpp @@ -1,8 +1,10 @@ #include "cru/base/Exception.h" -#include "cru/base/Format.h" - #include <cerrno> +#include <format> +#include <string_view> + +constexpr auto NO_MESSAGE = "No message."; namespace cru { Exception::Exception(std::string message, std::unique_ptr<std::exception> inner) @@ -13,9 +15,7 @@ Exception::Exception(StringView message, std::unique_ptr<std::exception> inner) Exception::~Exception() {} -const char* Exception::what() const noexcept { - return message_.c_str(); -} +const char* Exception::what() const noexcept { return message_.c_str(); } void Exception::AppendMessage(StringView additional_message) { message_ += " "; @@ -26,10 +26,21 @@ void Exception::AppendMessage(std::optional<StringView> additional_message) { if (additional_message) AppendMessage(*additional_message); } -ErrnoException::ErrnoException(String message) +ErrnoException::ErrnoException() : ErrnoException(NO_MESSAGE) {} + +ErrnoException::ErrnoException(int errno_code) + : ErrnoException(NO_MESSAGE, errno_code) {} + +ErrnoException::ErrnoException(std::string_view message) : ErrnoException(message, errno) {} -ErrnoException::ErrnoException(String message, int errno_code) - : Exception(Format(u"{}. Errno is {}.", message, errno_code)), +ErrnoException::ErrnoException(std::string_view message, int errno_code) + : Exception(std::format("{} Errno is {}.", message, errno_code)), errno_code_(errno_code) {} + +ErrnoException::ErrnoException(StringView message) + : ErrnoException(message.ToUtf8()) {} + +ErrnoException::ErrnoException(StringView message, int errno_code) + : ErrnoException(message.ToUtf8(), errno_code) {} } // namespace cru |