From 04ec4af02c38fc9474ebd392147fe7128a177298 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Sun, 12 Sep 2021 13:40:55 +0200 Subject: Added some std::error_code helpers * Added MakeWin32ErrorCode/MakeErrorCodeFromLastError * Fixed GetLastErrorAsString() implementation so it doesn't throw (!) --- zencore/include/zencore/except.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'zencore/include') 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 -- cgit v1.2.3