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 7431249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:15:59+00:00 2026-05-29T09:15:59+00:00

so I was trying to add AppDomain.CurrentDomain.UnhandledException handler to my application and it worked

  • 0

so I was trying to add “AppDomain.CurrentDomain.UnhandledException” handler to my application and it worked OK if I log the error to a text file. but when I try to use a MessageBox it never pops. is it another bug in .Net? any ideas?

here is my code sample:

   AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

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

and here is my handler method:

static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e)
{
    try
    {
       Exception ex = (Exception)e.ExceptionObject;

       MessageBox.Show("Whoops! Please contact the developers with "
                   + "the following information:\r\n\r\n" + ex.Message + ex.StackTrace,
                   "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

    }
    finally
    {
       Application.Exit();
    }
}

EDIT: I’ve tried all of the possible options but I still can’t see the MessageBox. Now the problem is when I run it from Visual C# (debug mode) it perfectly shows the box. but when I run the application directly from the debug/release folders it doesn’t shows the MessageBox and the Application keeps running like there is no error is happening…

  • 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-29T09:16:00+00:00Added an answer on May 29, 2026 at 9:16 am

    this example works for me in debug mode and release mode with vs2010 or not:

    using System;
    using System.Windows.Forms;
    
    namespace WinFormsStackOverflowSpielWiese
    {
      internal static class Program
      {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main() {
          System.Windows.Forms.Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
          System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
          AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new Form1());
        }
    
        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) {
          try {
            var exception = e.Exception != null ? e.Exception.Message + e.Exception.StackTrace : string.Empty;
            MessageBox.Show("Whoops! Please contact the developers with the following information:\r\n\r\n" + exception,
                            "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
          }
          finally {
            Application.Exit();
          }
        }
    
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
          try {
            var exception = e.ExceptionObject is Exception ? ((Exception)e.ExceptionObject).Message + ((Exception)e.ExceptionObject).StackTrace : string.Empty;
            MessageBox.Show("Whoops! Please contact the developers with the following information:\r\n\r\n" + exception,
                            "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
          }
          finally {
            Application.Exit();
          }
        }
      }
    }
    

    code for the form

    EDIT now with a timer, with the same result….

    using System.Windows.Forms;
    
    namespace WinFormsStackOverflowSpielWiese
    {
      public partial class Form1 : Form
      {
        private System.Threading.Timer myTimer;
    
        public Form1() {
          this.InitializeComponent();
    
          this.myTimer = new System.Threading.Timer(state =>
                                                      {
                                                        var i = 0;
                                                        var s = 100 / i;
                                                      }
                                                    , null, 5000, 5000);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying add two columns in a text file that are seperated by
I'm trying add Taskbar Icon overlay with text to windows7 application icon, I did
I am trying to add addons in my application, but I don't want the
Trying to add an onclick handler to my tabs, and can't seem to get
Im trying to add some short file names to a Wise installer to fix
Im trying to add a directory foo to my repo, but there are some
I'm trying add a bold/strong tag the line headings of the follow string/text block:
im trying to add a css class in my javascript code but when i
Trying to add django-registration to my app. I have installed setup tools to use
I'm trying add a directory of jar files (or barring that, each jar file

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.