diff options
author | 杨宇千 <crupest@outlook.com> | 2019-03-28 20:39:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-28 20:39:36 +0800 |
commit | c45a6e62298e972f5945f5f3461ed723aea80317 (patch) | |
tree | f46ef303ee87a8e3814ea8743bd7062d432bfee3 /src/exception.cpp | |
parent | b028e74a48de181ca078ad3bf4ababf4fa146cd3 (diff) | |
parent | 37216f211b0e22205a3a0d3373d985fc68aea59b (diff) | |
download | cru-c45a6e62298e972f5945f5f3461ed723aea80317.tar.gz cru-c45a6e62298e972f5945f5f3461ed723aea80317.tar.bz2 cru-c45a6e62298e972f5945f5f3461ed723aea80317.zip |
Merge pull request #37 from crupest/render
Refactor.
Diffstat (limited to 'src/exception.cpp')
-rw-r--r-- | src/exception.cpp | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/exception.cpp b/src/exception.cpp index cb1ca2c7..dbc98453 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -1,40 +1,42 @@ #include "exception.hpp" -#include "format.hpp" - -namespace cru -{ - inline std::string HResultMakeMessage(HRESULT h_result, std::optional<MultiByteStringView> message) - { - char buffer[10]; - sprintf_s(buffer, "%#08x", h_result); - - if (message.has_value()) - return Format("An HResultError is thrown. HRESULT: {}.\nAdditional message: {}\n", buffer, message.value()); - else - return Format("An HResultError is thrown. HRESULT: {}.\n", buffer); - } - - HResultError::HResultError(HRESULT h_result, std::optional<MultiByteStringView> additional_message) - : runtime_error(HResultMakeMessage(h_result, std::nullopt)), h_result_(h_result) - { - - } - - inline std::string Win32MakeMessage(DWORD error_code, std::optional<MultiByteStringView> message) - { - char buffer[10]; - sprintf_s(buffer, "%#04x", error_code); - - if (message.has_value()) - return Format("Last error code: {}.\nAdditional message: {}\n", buffer, message.value()); - else - return Format("Last error code: {}.\n", buffer); - } - - Win32Error::Win32Error(DWORD error_code, std::optional<MultiByteStringView> additional_message) - : runtime_error(Win32MakeMessage(error_code, std::nullopt)), error_code_(error_code) - { - - } +#include "util/format.hpp" + +namespace cru { +using util::Format; + +inline std::string HResultMakeMessage( + HRESULT h_result, std::optional<MultiByteStringView> message) { + char buffer[10]; + sprintf_s(buffer, "%#08x", h_result); + + if (message.has_value()) + return Format( + "An HResultError is thrown. HRESULT: {}.\nAdditional message: {}\n", + buffer, message.value()); + else + return Format("An HResultError is thrown. HRESULT: {}.\n", buffer); } + +HResultError::HResultError( + HRESULT h_result, std::optional<MultiByteStringView> additional_message) + : runtime_error(HResultMakeMessage(h_result, std::nullopt)), + h_result_(h_result) {} + +inline std::string Win32MakeMessage( + DWORD error_code, std::optional<MultiByteStringView> message) { + char buffer[10]; + sprintf_s(buffer, "%#04x", error_code); + + if (message.has_value()) + return Format("Last error code: {}.\nAdditional message: {}\n", buffer, + message.value()); + else + return Format("Last error code: {}.\n", buffer); +} + +Win32Error::Win32Error(DWORD error_code, + std::optional<MultiByteStringView> additional_message) + : runtime_error(Win32MakeMessage(error_code, std::nullopt)), + error_code_(error_code) {} +} // namespace cru |