diff options
| author | Stefan Boberg <[email protected]> | 2021-09-12 13:40:55 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-12 13:40:55 +0200 |
| commit | 04ec4af02c38fc9474ebd392147fe7128a177298 (patch) | |
| tree | 51ba9ffd6ca2b9dfd767f8b3361ef36382755c53 /zencore/include | |
| parent | HttpResponse enum -> HttpResponseCode (diff) | |
| download | zen-04ec4af02c38fc9474ebd392147fe7128a177298.tar.xz zen-04ec4af02c38fc9474ebd392147fe7128a177298.zip | |
Added some std::error_code helpers
* Added MakeWin32ErrorCode/MakeErrorCodeFromLastError
* Fixed GetLastErrorAsString() implementation so it doesn't throw (!)
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/except.h | 13 |
1 files changed, 13 insertions, 0 deletions
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 |