Created
May 1, 2019 07:46
-
-
Save 0xced/84821a5243bd0f6425daec84d44e75b5 to your computer and use it in GitHub Desktop.
Display exceptions with a TaskDialog or a MessageBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For setting up unhandled exceptions handlers: https://stackoverflow.com/questions/5762526/how-can-i-make-something-that-catches-all-unhandled-exceptions-in-a-winforms-a | |
// Using Ookii.Dialogs: https://www.nuget.org/packages?q=Ookii.Dialogs | |
static void DisplayException(Exception exception) | |
{ | |
var baseException = exception.GetBaseException(); | |
var title = @"Error: " + baseException.GetType().Name; | |
var message = baseException.Message; | |
if (TaskDialog.OSSupportsTaskDialogs) | |
{ | |
using (var dialog = new TaskDialog()) | |
{ | |
dialog.MainIcon = TaskDialogIcon.Error; | |
dialog.WindowTitle = title; | |
dialog.Content = message; | |
dialog.ExpandedControlText = @"Hide details"; | |
dialog.CollapsedControlText = @"Show details"; | |
dialog.ExpandedInformation = exception.StackTrace; | |
dialog.Buttons.Add(new TaskDialogButton(ButtonType.Ok)); | |
dialog.Show(); | |
} | |
} | |
else | |
{ | |
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment