diff options
author | crupest <crupest@outlook.com> | 2018-09-19 01:15:01 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-19 01:15:01 +0800 |
commit | 85bb4d466efeb2540363065d7c0987a9d60f70e9 (patch) | |
tree | ea5e5aa738afb37a2d3bc4e74f9be64c15f3d188 /CruUI/exception.cpp | |
parent | 4710715102df3806479985679bd8048631ccaab5 (diff) | |
download | cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.tar.gz cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.tar.bz2 cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.zip |
finish animation!!!
Diffstat (limited to 'CruUI/exception.cpp')
-rw-r--r-- | CruUI/exception.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/CruUI/exception.cpp b/CruUI/exception.cpp index 45af254d..38075247 100644 --- a/CruUI/exception.cpp +++ b/CruUI/exception.cpp @@ -1,29 +1,34 @@ #include "exception.h" -#include <sstream> -#include <iomanip> +#include <fmt/format.h> namespace cru { - HResultError::HResultError(const HRESULT h_result) - : runtime_error(MakeMessage(h_result, std::nullopt)), h_result_(h_result) - { + inline std::string HResultMakeMessage(HRESULT h_result, std::optional<std::string> message) + { + if (message.has_value()) + return fmt::format("An HResultError is thrown. HRESULT: {:#08x}.\n", h_result); + else + return fmt::format("An HResultError is thrown. HRESULT: {:#08x}.\nAdditional message: {}\n", h_result, message.value()); + } - } + HResultError::HResultError(HRESULT h_result, std::optional<std::string_view> additional_message) + : runtime_error(HResultMakeMessage(h_result, std::nullopt)), h_result_(h_result) + { - HResultError::HResultError(const HRESULT h_result, const std::string& message) - : runtime_error(MakeMessage(h_result, std::make_optional(message))), h_result_(h_result) - { + } - } + inline std::string Win32MakeMessage(DWORD error_code, std::optional<std::string> message) + { + if (message.has_value()) + return fmt::format("Last error code: {:#04x}.\n", error_code); + else + return fmt::format("Last error code: {:#04x}.\nAdditional message: {}\n", error_code, message.value()); + } - std::string HResultError::MakeMessage(HRESULT h_result, std::optional<std::string> message) - { - std::stringstream ss; - ss << "An HResultError is thrown. HRESULT: 0x" << std::setfill('0') - << std::setw(sizeof h_result * 2) << std::hex << h_result << "."; - if (message.has_value()) - ss << "Additional message: " << message.value(); - return ss.str(); - } + Win32Error::Win32Error(DWORD error_code, std::optional<std::string_view> additional_message) + : runtime_error(Win32MakeMessage(error_code, std::nullopt)), error_code_(error_code) + { + + } } |