diff options
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/except.cpp | 8 | ||||
| -rw-r--r-- | zencore/include/zencore/except.h | 13 |
2 files changed, 20 insertions, 1 deletions
diff --git a/zencore/except.cpp b/zencore/except.cpp index 00cb826f6..9bd447308 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -28,7 +28,13 @@ ThrowLastError(std::string_view Message) std::string GetLastErrorAsString() { - throw std::error_code(::GetLastError(), std::system_category()).message(); + return GetWindowsErrorAsString(::GetLastError()); +} + +std::string +GetWindowsErrorAsString(uint32_t Win32ErrorCode) +{ + return std::error_code(Win32ErrorCode, std::system_category()).message(); } void diff --git a/zencore/include/zencore/except.h b/zencore/include/zencore/except.h index 0ae31dc71..8625f01d0 100644 --- a/zencore/include/zencore/except.h +++ b/zencore/include/zencore/except.h @@ -55,5 +55,18 @@ ThrowSystemException(const char* Message) ZENCORE_API void ThrowLastError(std::string_view Message); ZENCORE_API void ThrowLastError(std::string_view Message, const std::source_location& Location); ZENCORE_API std::string GetLastErrorAsString(); +ZENCORE_API std::string GetWindowsErrorAsString(uint32_t Win32ErrorCode); + +inline std::error_code +MakeWin32ErrorCode(uint32_t Win32ErrorCode) noexcept +{ + return std::error_code(Win32ErrorCode, std::system_category()); +} + +inline std::error_code +MakeErrorCodeFromLastError() noexcept +{ + return std::error_code(::GetLastError(), std::system_category()); +} } // namespace zen |