diff options
author | crupest <crupest@outlook.com> | 2023-12-16 21:16:46 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-12-16 21:16:46 +0800 |
commit | 9514626f02d21edef33fa6212aa47fdb3c115fe9 (patch) | |
tree | c3bf22d34d1eedcb90d8c5380f0c8d59dd7b1e80 | |
parent | c9555b5649bd1e886f96276eb392d65fffe2eb47 (diff) | |
download | cru-9514626f02d21edef33fa6212aa47fdb3c115fe9.tar.gz cru-9514626f02d21edef33fa6212aa47fdb3c115fe9.tar.bz2 cru-9514626f02d21edef33fa6212aa47fdb3c115fe9.zip |
Optimize exception constructor.
-rw-r--r-- | include/cru/common/Exception.h | 11 | ||||
-rw-r--r-- | src/common/Exception.cpp | 6 |
2 files changed, 8 insertions, 9 deletions
diff --git a/include/cru/common/Exception.h b/include/cru/common/Exception.h index 06a10030..0aee871c 100644 --- a/include/cru/common/Exception.h +++ b/include/cru/common/Exception.h @@ -9,8 +9,7 @@ namespace cru { #endif class CRU_BASE_API Exception : public std::exception { public: - Exception(); - explicit Exception(String message); + explicit Exception(String message = {}); CRU_DEFAULT_COPY(Exception) CRU_DEFAULT_MOVE(Exception) @@ -40,9 +39,11 @@ class CRU_BASE_API TextEncodeException : public Exception { class ErrnoException : public Exception { public: - ErrnoException() : ErrnoException(String{}) {} - explicit ErrnoException(const String& message); - ErrnoException(const String& message, int errno_code); + /** + * @brief will retrieve errno automatically. + */ + explicit ErrnoException(String message = {}); + ErrnoException(String message, int errno_code); CRU_DELETE_COPY(ErrnoException) CRU_DELETE_MOVE(ErrnoException) diff --git a/src/common/Exception.cpp b/src/common/Exception.cpp index e1e3e128..37fa0038 100644 --- a/src/common/Exception.cpp +++ b/src/common/Exception.cpp @@ -5,8 +5,6 @@ #include <cerrno> namespace cru { -Exception::Exception() {} - Exception::Exception(String message) : message_(std::move(message)) {} Exception::~Exception() {} @@ -28,10 +26,10 @@ void Exception::AppendMessage(std::optional<StringView> additional_message) { if (additional_message) AppendMessage(*additional_message); } -ErrnoException::ErrnoException(const String& message) +ErrnoException::ErrnoException(String message) : ErrnoException(message, errno) {} -ErrnoException::ErrnoException(const String& message, int errno_code) +ErrnoException::ErrnoException(String message, int errno_code) : Exception(Format(u"{}. Errno is {}.", message, errno_code)), errno_code_(errno_code) {} } // namespace cru |