Skip to main content
added 1024 characters in body
Source Link
Scott Wylie
  • 4.7k
  • 2
  • 37
  • 48

Does it stop by giving you an exception or does it just completely stop the execution of your application? If you don't have the UnHandledExceptionHandler in your code it can look like it just stops but you actually have an exception.

private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)UPDATE: Here is what your Main method should look like to capture unhandled exceptions as try/catch don't always work.

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
    {
        throw new NotImplementedException();
    }

    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        // You should/MAY see an error right here.
        throw new NotImplementedException();
    }

Does it stop by giving you an exception or does it just completely stop the execution of your application? If you don't have the UnHandledExceptionHandler in your code it can look like it just stops but you actually have an exception.

private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)

Does it stop by giving you an exception or does it just completely stop the execution of your application? If you don't have the UnHandledExceptionHandler in your code it can look like it just stops but you actually have an exception.

UPDATE: Here is what your Main method should look like to capture unhandled exceptions as try/catch don't always work.

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
    {
        throw new NotImplementedException();
    }

    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        // You should/MAY see an error right here.
        throw new NotImplementedException();
    }
Source Link
Scott Wylie
  • 4.7k
  • 2
  • 37
  • 48

Does it stop by giving you an exception or does it just completely stop the execution of your application? If you don't have the UnHandledExceptionHandler in your code it can look like it just stops but you actually have an exception.

private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)