From 173494641a124451df30882d91aa5eb4daba8cb7 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Wed, 2 Aug 2023 10:37:27 +0100 Subject: [PATCH] Show all inner exceptions for connectivity dialog maybe using a viewmodel isnt a bad idea after all... --- .../Dialogs/ConnectivityDialog.xaml.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs index b34a905..c16025a 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml.cs @@ -16,17 +16,12 @@ namespace Bloxstrap.UI.Elements.Dialogs { public ConnectivityDialog(string targetName, string description, Exception exception) { - Exception? innerException = exception.InnerException; - InitializeComponent(); TitleTextBlock.Text = $"{App.ProjectName} is unable to connect to {targetName}"; DescriptionTextBlock.Text = description; - ErrorRichTextBox.Selection.Text = $"{exception.GetType()}: {exception.Message}"; - - if (innerException is not null) - ErrorRichTextBox.Selection.Text += $"\n\n===== Inner Exception =====\n{innerException.GetType()}: {innerException.Message}"; + AddException(exception); CloseButton.Click += delegate { @@ -41,5 +36,18 @@ namespace Bloxstrap.UI.Elements.Dialogs PInvoke.FlashWindow((HWND)hWnd, true); }; } + + private void AddException(Exception exception, bool inner = false) + { + if (!inner) + ErrorRichTextBox.Selection.Text = $"{exception.GetType()}: {exception.Message}"; + + if (exception.InnerException is null) + return; + + ErrorRichTextBox.Selection.Text += $"\n\n[Inner Exception]\n{exception.InnerException.GetType()}: {exception.InnerException.Message}"; + + AddException(exception.InnerException, true); + } } }