From f6177004578583996f3f343a79c560c79bb5dfcc Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sun, 6 Aug 2023 14:32:58 +0100 Subject: [PATCH] Unwrap inner exceptions when showing exception --- .../UI/Elements/Dialogs/ExceptionDialog.xaml | 2 +- .../UI/Elements/Dialogs/ExceptionDialog.xaml.cs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml index 54d8a51..a2c5418 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml @@ -6,7 +6,7 @@ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:local="clr-namespace:Bloxstrap.UI.Elements.Dialogs" mc:Ignorable="d" - Width="480" + Width="540" MinHeight="0" SizeToContent="Height" Background="{ui:ThemeResource ApplicationBackgroundBrush}" diff --git a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs index e53485d..7915ae4 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs @@ -22,10 +22,8 @@ namespace Bloxstrap.UI.Elements.Dialogs InitializeComponent(); Title = RootTitleBar.Title = $"{App.ProjectName} Exception"; - 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); if (!App.Logger.Initialized) LocateLogFileButton.Content = "Copy log contents"; @@ -66,5 +64,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); + } } }