// Copyright Epic Games, Inc. All Rights Reserved. #include #include namespace zen { #if ZEN_PLATFORM_WINDOWS void ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string_view Message) { 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); } } #endif // ZEN_PLATFORM_WINDOWS void ThrowLastError(std::string_view Message) { throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), std::string(Message)); } std::string GetLastErrorAsString() { return GetErrorAsString(zen::GetLastError()); } std::string GetErrorAsString(uint32_t ErrorCode) { return std::error_code(ErrorCode, std::system_category()).message(); } void ThrowLastError(std::string_view Message, const std::source_location& Location) { using namespace fmt::literals; throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), "{}({}): {}"_format(Location.file_name(), Location.line(), Message)); } } // namespace zen