c# question

De Silva KRD 1 Reputation point

how to fix exception unhandled in c#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,524 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,286 Reputation points

    First thing is to learn how to write unit test against code then when in doubt setup an unhandled exception handler which is implemented differently for different types of projects. For a Windows Form project check out my NuGet package KP.ExceptionHandling and learn how to use it in the following GitHub repository on the front page.

    Base code to implement

    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  
            /// <summary>  
            ///  The main entry point for the application.  
            /// </summary>  
            static void Main()  
                // Handling UI thread exceptions to the event.  
                Application.ThreadException += UnhandledExceptions.Application_ThreadException;  
                // For handling non-UI thread exceptions to the event.   
                AppDomain.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" };  
    0 comments No comments