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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:34:29+00:00 2026-05-13T13:34:29+00:00

I have this code: 001 private void uiButton1_Click(object sender, EventArgs e) 002 { 003

  • 0

I have this code:

001 private void uiButton1_Click(object sender, EventArgs e)
002 {
003     string someString = "";
004     try
005     {
006         someString = ThisMethodThrowsAnException();
007     }
008     catch (Exception)
009     {        
010         throw;
011     }
012 }

The code does get to the “throw” in the catch but the standard winforms “unhandled exception” dialog never shows up.

ThisMethodThrowsAnException() is throwing an exception of type System.Exception. I have an event attached to Application.ThreadException. That event is not being hit in this case. uiButton is a standard winforms button. I created a button that throws an exception in its event handler and that exception is being caught by Application_ThreadException. All of the processing is happening on one thread.

For the life of me I can’t see why this code wouldn’t result in the normal exception box (which, since this is an app that only I use, is something that’s helpful). There are other places in this app where I’ve seen the standard exception dialog.

I have a button click handler that looks like this:

 private void button2_Click(object sender, EventArgs e)
    {
        throw new Exception("I are broke!"); 
    }

And a ThreadException handler that looks like this:

 static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            MessageBox.Show("Exception: " + e.Exception.Message); 
        }

I’m using UnhandledExceptionMode.Automatic. When I click the uiButton1 I do not get an exception message via Application_ThreadException. However if I add a throw new Exception just before the method call to ThisMethodThrowsAnException, I do get the MessageBox.

I do get a MessageBox via button2 (through Application_ThreadException).

So something is happening in ThisMethodThrowsAnException. The only thing I can think of is that it’s starting up a new thread, but that’s not the case when I debug through it.

If the exception was happening on a different thread would it get back to the catch block in uiButton1_Click?

  • 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-13T13:34:29+00:00Added an answer on May 13, 2026 at 1:34 pm

    The debugger is getting in the way. The Application class is aware that a debugger is attached to the program, it uses System.Diagnostics.Debugger.IsAttached(). If that’s the case, it does not use a try/catch block around the message loop and the Application.ThreadException event will not run.

    This is quite intentional. If the catch block were active, you would have a very hard time troubleshooting exceptions in your program. Without the catch block, the debugger will always stop and show you what is wrong.

    You can reproduce the runtime behavior. Add this line of code to your Main() method before the Run() call:

     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's no standard C++ way to emulate this because there… May 14, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer If I had this right your activity is returning the… May 14, 2026 at 8:25 pm
  • Editorial Team
    Editorial Team added an answer Solved it. Was using the wrong regex character. Works now. May 14, 2026 at 8:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.