From f6908c4f714f629bfe74babc731b6bbe0448ef2d Mon Sep 17 00:00:00 2001 From: Vladimir Belyavsky Date: Sat, 15 Apr 2023 12:24:41 +0300 Subject: [PATCH] QNetworkInformation[Win]: Improve WinRT exceptions handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - handle only winrt::hresult_error exceptions, as this is the only reported cases, so we don't need ellipsis there - print relevant warnings Pick-to: 6.5 Change-Id: Ibf18a7eab7862e2c20f5729545387ddc7ca42952 Reviewed-by: MÃ¥rten Nordheim --- .../networklistmanager/qnetworklistmanagerevents.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp index eb6b6888aff..7d6fd6d5c13 100644 --- a/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp +++ b/src/plugins/networkinformation/networklistmanager/qnetworklistmanagerevents.cpp @@ -203,7 +203,9 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile NetworkAdapter adapter(nullptr); try { adapter = profile.NetworkAdapter(); - } catch (...) { + } catch (const winrt::hresult_error &ex) { + qCWarning(lcNetInfoNLM) << "Failed to obtain network adapter:" + << QSystemError::windowsComString(ex.code()); // pass, we will return Unknown anyway } if (adapter == nullptr) @@ -231,7 +233,9 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile ConnectionCost cost(nullptr); try { cost = profile.GetConnectionCost(); - } catch (...) { + } catch (const winrt::hresult_error &ex) { + qCWarning(lcNetInfoNLM) << "Failed to obtain connection cost:" + << QSystemError::windowsComString(ex.code()); // pass, we return false if we get an empty object back anyway } if (cost == nullptr) @@ -247,7 +251,9 @@ void QNetworkListManagerEvents::emitWinRTUpdates() ConnectionProfile profile = nullptr; try { profile = NetworkInformation::GetInternetConnectionProfile(); - } catch (...) { + } catch (const winrt::hresult_error &ex) { + qCWarning(lcNetInfoNLM) << "Failed to obtain connection profile:" + << QSystemError::windowsComString(ex.code()); // pass, we would just return early if we get an empty object back anyway } if (profile == nullptr)