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?