KP.ExceptionHandling 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package KP.ExceptionHandling --version 1.0.1                
NuGet\Install-Package KP.ExceptionHandling -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KP.ExceptionHandling" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KP.ExceptionHandling --version 1.0.1                
#r "nuget: KP.ExceptionHandling, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KP.ExceptionHandling as a Cake Addin
#addin nuget:?package=KP.ExceptionHandling&version=1.0.1

// Install KP.ExceptionHandling as a Cake Tool
#tool nuget:?package=KP.ExceptionHandling&version=1.0.1                

About

Simple code sample for application-wide exception handler to write unhandled exceptions to a log file.

Prerequisites

To run this project as is in this repository.

  • VS2019
  • .NET Core 5

TechNet Wiki article

Unhandled runtime exceptions window forms (C#)

Implement

using System;
using System.Windows.Forms;
using ExceptionHandling;

namespace ThreadExceptionWindowsFormsApp
{
    /// <summary>
    /// Rig for unhandled exceptions.
    /// Note Text property set on error form is for demo purposes only
    /// </summary>
    static class Program
    {

        [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;


            Application.Run(new Form1());

        }
        /// <summary>
        /// Display window informing application most close
        /// </summary>
        private static void OnProcessingCompletedEvent()
        {
            var f = new AppErrorForm { Text = @"Your title goes here" };
            f.ShowDialog();
            Application.Exit();
        }
    }
}

Source code

Source code for both the class project and test application.

Get source without all projects

With Git installed, create a batch file with the following contents, save, run and add the cloned projects to your solution.

mkdir code
cd code
git init
git remote add -f origin https://github.com/karenpayneoregon/csharp-features
git sparse-checkout init --cone
git sparse-checkout add ExceptionHandling
git sparse-checkout add ThreadExceptionWindowsFormsApp
git pull origin master
:clean-up
del .gitattributes
del .gitignore
del .yml
del .editorconfig
del *.md
del *.sln
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 522 5/23/2021
1.0.1 444 2/4/2021
1.0.0 441 2/3/2021

C#, .NET5, Desktop,Exception handling