From 1dab244aaad8694ba37ef43caedd8c8ba0310c00 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 5 Nov 2018 20:54:48 +0800 Subject: ... --- src/exception.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/exception.cpp') diff --git a/src/exception.cpp b/src/exception.cpp index a1d59ceb..92face96 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -1,32 +1,38 @@ #include "exception.h" -#include +#include "format.h" namespace cru { - inline std::string HResultMakeMessage(HRESULT h_result, std::optional message) + inline std::string HResultMakeMessage(HRESULT h_result, std::optional message) { + char buffer[10]; + sprintf_s(buffer, "%#08x", h_result); + if (message.has_value()) - return fmt::format("An HResultError is thrown. HRESULT: {:#08x}.\nAdditional message: {}\n", h_result, message.value()); + return Format("An HResultError is thrown. HRESULT: {}.\nAdditional message: {}\n", buffer, message.value()); else - return fmt::format("An HResultError is thrown. HRESULT: {:#08x}.\n", h_result); + return Format("An HResultError is thrown. HRESULT: {}.\n", buffer); } - HResultError::HResultError(HRESULT h_result, std::optional additional_message) + HResultError::HResultError(HRESULT h_result, std::optional additional_message) : runtime_error(HResultMakeMessage(h_result, std::nullopt)), h_result_(h_result) { } - inline std::string Win32MakeMessage(DWORD error_code, std::optional message) + inline std::string Win32MakeMessage(DWORD error_code, std::optional message) { + char buffer[10]; + sprintf_s(buffer, "%#04x", error_code); + if (message.has_value()) - return fmt::format("Last error code: {:#04x}.\nAdditional message: {}\n", error_code, message.value()); + return Format("Last error code: {}.\nAdditional message: {}\n", buffer, message.value()); else - return fmt::format("Last error code: {:#04x}.\n", error_code); + return Format("Last error code: {}.\n", buffer); } - Win32Error::Win32Error(DWORD error_code, std::optional additional_message) + Win32Error::Win32Error(DWORD error_code, std::optional additional_message) : runtime_error(Win32MakeMessage(error_code, std::nullopt)), error_code_(error_code) { -- cgit v1.2.3