https://github.com/karenpayneoregon/exception-handler
Provides an easy way to handle unhandled exceptions in a Windows Form application
https://github.com/karenpayneoregon/exception-handler
csharp-code csharp-core csharp-library unhandled-exception-handler unhandled-exceptions visual-studio
Last synced: 2 months ago
JSON representation
Provides an easy way to handle unhandled exceptions in a Windows Form application
- Host: GitHub
- URL: https://github.com/karenpayneoregon/exception-handler
- Owner: karenpayneoregon
- Created: 2021-02-04T14:48:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-23T15:45:26.000Z (about 4 years ago)
- Last Synced: 2025-03-30T05:41:13.238Z (3 months ago)
- Topics: csharp-code, csharp-core, csharp-library, unhandled-exception-handler, unhandled-exceptions, visual-studio
- Language: C#
- Homepage:
- Size: 977 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# About
Source and code sample for [KP.ExceptionHandling NuGet package](https://www.nuget.org/packages/KP.ExceptionHandling/).


### Microsoft TechNet article
https://social.technet.microsoft.com/wiki/contents/articles/54209.unhandled-runtime-exceptions-window-forms-c.aspx### Log viewer

### Example
- Add the above package
- Modifiy code for OnProcessingCompletedEvent```csharp
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using ExceptionHandling;namespace KP_ExceptionPackageTest
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);// Handling UI thread exceptions to the event.
Application.ThreadException += UnhandledExceptions.Application_ThreadException;// For handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException +=
UnhandledExceptions.CurrentDomain_UnhandledException;// Indicates capturing exception has completed
UnhandledExceptions.OnProcessingCompletedEvent += OnProcessingCompletedEvent;// TODO Change this to your startup form
Application.Run(new Form1());
}private static void OnProcessingCompletedEvent()
{
var f = new AppErrorForm { Text = @"Your title goes here" };
f.ShowDialog();
Application.Exit();
}
}
}```