aboutsummaryrefslogtreecommitdiff
path: root/src/win/exception.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-23 23:50:00 +0800
committercrupest <crupest@outlook.com>2020-05-23 23:50:00 +0800
commitf3a8fd608a9776ef0a5f547da918a32cf6074060 (patch)
tree85b320479296ae12339ee1e28bab66ab001cb44b /src/win/exception.cpp
parent75ff8a6a05afd02aaadf7e3049b0a0e305241182 (diff)
downloadcru-f3a8fd608a9776ef0a5f547da918a32cf6074060.tar.gz
cru-f3a8fd608a9776ef0a5f547da918a32cf6074060.tar.bz2
cru-f3a8fd608a9776ef0a5f547da918a32cf6074060.zip
...
Diffstat (limited to 'src/win/exception.cpp')
-rw-r--r--src/win/exception.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/win/exception.cpp b/src/win/exception.cpp
index e0f114b5..fde3ec6f 100644
--- a/src/win/exception.cpp
+++ b/src/win/exception.cpp
@@ -1,36 +1,32 @@
#include "cru/win/exception.hpp"
-#include "cru/common/format.hpp"
+#include <fmt/format.h>
+#include <optional>
namespace cru::platform::win {
-using util::Format;
inline std::string HResultMakeMessage(HRESULT h_result,
- const std::string_view* message) {
- char buffer[20];
- sprintf_s(buffer, "%#08x", h_result);
-
- if (message)
- return Format("HRESULT: {}.\nMessage: {}\n", buffer, *message);
+ std::optional<std::string_view> message) {
+ if (message.has_value())
+ return fmt::format(FMT_STRING("HRESULT: {:#08x}. Message: {}"), h_result,
+ *message);
else
- return Format("HRESULT: {}.\n", buffer);
+ return fmt::format(FMT_STRING("HRESULT: {:#08x}."), h_result);
}
HResultError::HResultError(HRESULT h_result)
- : PlatformException(HResultMakeMessage(h_result, nullptr)),
+ : PlatformException(HResultMakeMessage(h_result, std::nullopt)),
h_result_(h_result) {}
HResultError::HResultError(HRESULT h_result,
const std::string_view& additional_message)
- : PlatformException(HResultMakeMessage(h_result, &additional_message)),
+ : PlatformException(HResultMakeMessage(h_result, additional_message)),
h_result_(h_result) {}
inline std::string Win32MakeMessage(DWORD error_code,
- const std::string_view& message) {
- char buffer[20];
- sprintf_s(buffer, "%#04x", error_code);
-
- return Format("Last error code: {}.\nMessage: {}\n", buffer, message);
+ std::string_view message) {
+ return fmt::format("Last error code: {:#04x}.\nMessage: {}\n", error_code,
+ message);
}
Win32Error::Win32Error(const std::string_view& message)