diff options
| author | Stefan Boberg <[email protected]> | 2021-05-21 21:17:12 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-21 21:17:12 +0200 |
| commit | 9f62b35a7380db253cce3310fa5208b8c8e20ef5 (patch) | |
| tree | ea6bdb2a876649c2eb5e1142d9c1a2a2d1c96ca8 /zencore/except.cpp | |
| parent | Renamed CasBlobFile -> BasicFile (diff) | |
| download | zen-9f62b35a7380db253cce3310fa5208b8c8e20ef5.tar.xz zen-9f62b35a7380db253cce3310fa5208b8c8e20ef5.zip | |
Cleaned up exception handling
We now use std::system_error where possible to report Win32 system errors. We still have WindowsException for general HRESULT based errors but we should phase it out where possible
Diffstat (limited to 'zencore/except.cpp')
| -rw-r--r-- | zencore/except.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/zencore/except.cpp b/zencore/except.cpp index b02122f58..882f69f9a 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -1,17 +1,27 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include <zencore/except.h> +#include <system_error> namespace zen { void -ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] const char* Message) +ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string_view Message) { - // TODO - - int ErrValue = hRes; + if (HRESULT_FACILITY(hRes) == FACILITY_WIN32) + { + throw std::system_error(std::error_code(hRes & 0xffff, std::system_category()), std::string(Message)); + } + else + { + throw WindowsException(hRes, Message); + } +} - throw std::system_error(ErrValue, std::system_category(), Message); +void +ThrowLastError(std::string_view Message) +{ + throw std::system_error(std::error_code(::GetLastError(), std::system_category()), std::string(Message)); } } // namespace zen |