aboutsummaryrefslogtreecommitdiff
path: root/src/base/Exception.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/Exception.cpp')
-rw-r--r--src/base/Exception.cpp27
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