Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShowExceptionmethod to BaseSamplePage #275

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

brunosonnino
Copy link
Contributor

Fixes #175
Fixes #176

Copy link
Member

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - we should make this more generic so it can be used by all samples.

{
var msg = optionalMessage ?? ex switch
{
COMException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we should have this code in the sample itself as this method can be generalized for all samples, not just for WCR samples. The ShowException method should be very general

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could live in a simple static class (in a SharedCode file). The file would use the XamlRoot from the static App.Window?.Content.XamlRoot (probably) and same for RootFrame.

@@ -15,13 +18,29 @@ internal partial class BaseSamplePage : Page
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
App.Current.UnhandledException += Current_UnhandledException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this handle all app exception and not just the sample exception?

"The WCL is in an unstable state.\nRebooting the machine will restart the WCL.",
_ => $"Error:\n{ex.Message}{(optionalMessage != null ? "\n" + optionalMessage : string.Empty)}"
};
ContentDialog exceptionDialog = new()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a copy exception details button here

{
var msg = optionalMessage ?? ex switch
{
COMException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could live in a simple static class (in a SharedCode file). The file would use the XamlRoot from the static App.Window?.Content.XamlRoot (probably) and same for RootFrame.

Comment on lines +206 to +210
Loader.Visibility = Visibility.Collapsed;
StopBtn.Visibility = Visibility.Collapsed;
_cts?.Dispose();
_cts = null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in the finally block, or outside the catch?

@@ -60,6 +61,10 @@ private static ChatOptions GetDefaultChatOptions()
{
await phiSilicaClient.InitializeAsync(cancellationToken);
}
catch (COMException ex) when (ex.Message.Contains("the rpc server is unavailable", System.StringComparison.CurrentCultureIgnoreCase))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are handling this here and throwing, this raises the question of if we should handle any exception here at all. I mean, why return null and not throw always, if there is an exception that is being handled elsewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants