Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3286236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:21:25+00:00 2026-05-17T20:21:25+00:00

Just a quick question. I can get a form to show with other exceptions,

  • 0

Just a quick question.

I can get a form to show with other exceptions, but with the type I’m asking about, I get the system “application is no longer working” dialog:

Program.cs:

        #if !DEBUG
        // Add the event handler for handling UI thread exceptions to the event.
        Application.ThreadException += new ThreadExceptionEventHandler(Logging.Application_ThreadException);

        // Set the unhandled exception mode to force all Windows Forms errors to go through our handler.
        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

        // Add the event handler for handling non-UI thread exceptions to the event. 
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Logging.CurrentDomain_UnhandledException);
        #endif

        throw new Exception();

Logging.cs:

    public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        ExceptionHandler((Exception)e.ExceptionObject, true);
    }

    private static void ExceptionHandler(Exception e, bool isFatal)
    {
        LogException(e, isFatal);

        //if (!isFatal)
        //{
            FormException formException = new FormException(isFatal);
            formException.Show();
        //}
        //else // It seems that showing a form when you have an unhandled exception isn't a good idea...
        //{
        //    MessageBox.Show("Crashed",
        //        Program.Name,
        //        MessageBoxButtons.OK,
        //        MessageBoxIcon.Stop);
        //    Program.Exit();
        //}
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:21:26+00:00Added an answer on May 17, 2026 at 8:21 pm

    Maybe this article will be helpful A Simple Class to Catch Unhandled Exceptions in WinForms

    EDIT:
    I check myself:

        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
                                                              {
                                                                  using (var form = new Form1())
                                                                  {
                                                                      form.ShowDialog();
                                                                  }
                                                              };
    
            throw new Exception();
        }
    

    Worked as expected. So can you show your code which doesn’t work?


    Also from article:

       public UnhandledExceptionDlg()
        {
            // Add the event handler for handling UI thread exceptions to the event:
            Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionFunction);
    
            // Set the unhandled exception mode to force all Windows Forms errors to go through our handler:
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    
            // Add the event handler for handling non-UI thread exceptions to the event:
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionFunction);
        }
    
    
        private void UnhandledExceptionFunction(Object sender, UnhandledExceptionEventArgs args)
        {
            // Suppress the Dialog in Debug mode:
            #if !DEBUG
            ShowUnhandledExceptionDlg((Exception)args.ExceptionObject);
            #endif
        }
    
        private void ShowUnhandledExceptionDlg(Exception e)
        {
            Exception unhandledException = e;
    
            if(unhandledException == null)
                unhandledException = new Exception("Unknown unhandled Exception was occurred!");
    
            UnhandledExDlgForm exDlgForm = new UnhandledExDlgForm();
            try
            {
                string appName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
                exDlgForm.Text = appName;
                exDlgForm.labelTitle.Text = String.Format(exDlgForm.labelTitle.Text, appName);
                exDlgForm.checkBoxRestart.Text = String.Format(exDlgForm.checkBoxRestart.Text, appName);
                exDlgForm.checkBoxRestart.Checked = this.RestartApp;
    
                // Do not show link label if OnShowErrorReport is not handled
                exDlgForm.labelLinkTitle.Visible = (OnShowErrorReport != null);
                exDlgForm.linkLabelData.Visible = (OnShowErrorReport != null);
    
                // Disable the Button if OnSendExceptionClick event is not handled
                exDlgForm.buttonSend.Enabled = (OnSendExceptionClick != null);
    
                // Attach reflection to checkbox checked status
                exDlgForm.checkBoxRestart.CheckedChanged += delegate(object o, EventArgs ev)
                {
                    this._dorestart = exDlgForm.checkBoxRestart.Checked;
                };
    
                // Handle clicks on report link label
                exDlgForm.linkLabelData.LinkClicked += delegate(object o, LinkLabelLinkClickedEventArgs ev)
                {
                    if(OnShowErrorReport != null)
                    {
                        SendExceptionClickEventArgs ar = new SendExceptionClickEventArgs(true, unhandledException, _dorestart);
                        OnShowErrorReport(this, ar);
                    }
                };
    
                // Show the Dialog box:
                bool sendDetails = (exDlgForm.ShowDialog() == System.Windows.Forms.DialogResult.Yes);
    
                if(OnSendExceptionClick != null)
                {
                    SendExceptionClickEventArgs ar = new SendExceptionClickEventArgs(sendDetails, unhandledException, _dorestart);
                    OnSendExceptionClick(this, ar);
                }
            }
            finally
            {
                exDlgForm.Dispose();
            }
        }
    

    So it shows form too…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a quick question: I am a CS undergrad and have only had experience
just a quick question, if I have a matrix has n rows and m
I am working with a huge list of URL's. Just a quick question I
Just a quick database design question: Do you ALWAYS use an ID field in
A quick Google search of this issue shows it's common, I just can't for
I just want a quick way (and preferably not using a while loop)of createing
I was just writing some quick code and noticed this complier error Using the
I'm just wondering if there is a quick way to echo undefined variables without
Just what the title says, I need to change the password for an existing
Just looking for the first step basic solution here that keeps the honest people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.