From 98177383073da2711e651f53918ad727329cb162 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Tue, 5 May 2020 09:36:09 -0700 Subject: [PATCH] Catch exception when trying to share (#1203) * Fix crash * Fix errors --- .../GraphingCalculator.xaml.cpp | 43 +++++++++++++------ .../GraphingCalculator.xaml.h | 1 + 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp index 8b3e98f..4d1f818 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp @@ -211,11 +211,11 @@ wstringstream GraphingCalculator::FormatTraceValue(double min, double max, float { wstringstream traceValueString; - // Extract precision we will round to + // Extract precision we will round to auto precision = static_cast(floor(log10(max - min)) - 3); // Determine if we want to show scientific notation instead - if (precision <= -7 || precision >= 7) + if (precision <= -7 || precision >= 7) { traceValueString << scientific; } @@ -282,11 +282,26 @@ void GraphingCalculator::ViewModel::set(GraphingCalculatorViewModel ^ vm) } } -void CalculatorApp::GraphingCalculator::OnShareClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) +void GraphingCalculator::OnShareClick(Object ^ sender, RoutedEventArgs ^ e) { // Ask the OS to start a share action. - DataTransferManager::ShowShareUI(); - TraceLogger::GetInstance()->LogGraphButtonClicked(GraphButton::Share, GraphButtonValue::None); + try + { + DataTransferManager::ShowShareUI(); + TraceLogger::GetInstance()->LogGraphButtonClicked(GraphButton::Share, GraphButtonValue::None); + } + catch (COMException ^ ex) + { + if (ex->HResult == RPC_E_SERVERCALL_RETRYLATER) + { + ShowShareError(); + TraceLogger::GetInstance()->LogPlatformException(ViewMode::Graphing, __FUNCTIONW__, ex); + } + else + { + throw; + } + } } // When share is invoked (by the user or programmatically) the event handler we registered will be called to populate the data package with the @@ -394,17 +409,21 @@ void GraphingCalculator::OnDataRequested(DataTransferManager ^ sender, DataReque } catch (Exception ^ ex) { + ShowShareError(); TraceLogger::GetInstance()->LogPlatformException(ViewMode::Graphing, __FUNCTIONW__, ex); - - // Something went wrong, notify the user. - - auto errDialog = ref new ContentDialog(); - errDialog->Content = resourceLoader->GetString(L"ShareActionErrorMessage"); - errDialog->CloseButtonText = resourceLoader->GetString(L"ShareActionErrorOk"); - errDialog->ShowAsync(); } } +void GraphingCalculator::ShowShareError() +{ + // Something went wrong, notify the user. + auto resourceLoader = ResourceLoader::GetForCurrentView(); + auto errDialog = ref new ContentDialog(); + errDialog->Content = resourceLoader->GetString(L"ShareActionErrorMessage"); + errDialog->CloseButtonText = resourceLoader->GetString(L"ShareActionErrorOk"); + errDialog->ShowAsync(); +} + void GraphingCalculator::GraphingControl_VariablesUpdated(Object ^, Object ^) { m_viewModel->UpdateVariables(GraphingControl->Variables); diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h index bff615c..f732b5e 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h @@ -106,6 +106,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo void OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e); std::wstringstream FormatTraceValue(double min, double max, float pointValue); void GraphViewButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void ShowShareError(); }; }