From 9f62b35a7380db253cce3310fa5208b8c8e20ef5 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 21 May 2021 21:17:12 +0200 Subject: 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 --- zencore/except.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'zencore/except.cpp') 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 +#include 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 -- cgit v1.2.3