QNetworkInformation[Win]: Improve WinRT exceptions handling

- 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 <marten.nordheim@qt.io>
This commit is contained in:
Vladimir Belyavsky 2023-04-15 12:24:41 +03:00 committed by Mårten Nordheim
parent ca978e2c12
commit f6908c4f71

View File

@ -203,7 +203,9 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile
NetworkAdapter adapter(nullptr); NetworkAdapter adapter(nullptr);
try { try {
adapter = profile.NetworkAdapter(); 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 // pass, we will return Unknown anyway
} }
if (adapter == nullptr) if (adapter == nullptr)
@ -231,7 +233,9 @@ QNetworkInformation::TransportMedium getTransportMedium(const ConnectionProfile
ConnectionCost cost(nullptr); ConnectionCost cost(nullptr);
try { try {
cost = profile.GetConnectionCost(); 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 // pass, we return false if we get an empty object back anyway
} }
if (cost == nullptr) if (cost == nullptr)
@ -247,7 +251,9 @@ void QNetworkListManagerEvents::emitWinRTUpdates()
ConnectionProfile profile = nullptr; ConnectionProfile profile = nullptr;
try { try {
profile = NetworkInformation::GetInternetConnectionProfile(); 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 // pass, we would just return early if we get an empty object back anyway
} }
if (profile == nullptr) if (profile == nullptr)