diff options
author | crupest <crupest@outlook.com> | 2018-09-01 23:28:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-01 23:28:28 +0800 |
commit | 956a401f9c955f26b7e661dc80f76bfc43fc4124 (patch) | |
tree | 8af088933c7bc08942478daddd55c92de8668359 /CruUI/exception.cpp | |
download | cru-956a401f9c955f26b7e661dc80f76bfc43fc4124.tar.gz cru-956a401f9c955f26b7e661dc80f76bfc43fc4124.tar.bz2 cru-956a401f9c955f26b7e661dc80f76bfc43fc4124.zip |
Initial commit
Diffstat (limited to 'CruUI/exception.cpp')
-rw-r--r-- | CruUI/exception.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 <sstream> +#include <iomanip> + +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<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(); + } +} |