diff options
Diffstat (limited to 'zencore/except.cpp')
| -rw-r--r-- | zencore/except.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/zencore/except.cpp b/zencore/except.cpp index 84e52ab9f..0167c406f 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -7,6 +7,41 @@ namespace zen { #if ZEN_PLATFORM_WINDOWS +class WindowsException : public std::exception +{ +public: + WindowsException(std::string_view Message) + { + m_hResult = HRESULT_FROM_WIN32(GetLastError()); + m_Message = Message; + } + + WindowsException(HRESULT hRes, std::string_view Message) + { + m_hResult = hRes; + m_Message = Message; + } + + WindowsException(HRESULT hRes, const char* Message, const char* Detail) + { + m_hResult = hRes; + + ExtendableStringBuilder<128> msg; + msg.Append(Message); + msg.Append(" (detail: '"); + msg.Append(Detail); + msg.Append("')"); + + m_Message = msg.c_str(); + } + + virtual const char* what() const override { return m_Message.c_str(); } + +private: + std::string m_Message; + HRESULT m_hResult; +}; + void ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string_view Message) { @@ -28,6 +63,12 @@ ThrowLastError(std::string_view Message) throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), std::string(Message)); } +void +ThrowSystemError(uint32_t ErrorCode, std::string_view Message) +{ + throw std::system_error(std::error_code(ErrorCode, std::system_category()), std::string(Message)); +} + std::string GetLastErrorAsString() { |