From 956a401f9c955f26b7e661dc80f76bfc43fc4124 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 1 Sep 2018 23:28:28 +0800 Subject: Initial commit --- CruUI/exception.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CruUI/exception.cpp (limited to 'CruUI/exception.cpp') diff --git a/CruUI/exception.cpp b/CruUI/exception.cpp new file mode 100644 index 00000000..45af254d --- /dev/null +++ b/CruUI/exception.cpp @@ -0,0 +1,29 @@ +#include "exception.h" + +#include +#include + +namespace cru +{ + HResultError::HResultError(const HRESULT h_result) + : runtime_error(MakeMessage(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) + { + + } + + std::string HResultError::MakeMessage(HRESULT h_result, std::optional 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(); + } +} -- cgit v1.2.3