In winforms, if an unhandled exception is encountered, a dialogue pops up alerting you that an exception occurred. This has buttons to continue execution or quit the application. What I was wondering is what state the app continues from if you select the continue button. My instinct would have been that it operated like in a debugger, continuing on the next statement after the exception, but this doesn't seem to be the case. To demonstrate this, I made a winforms app with a TextBox textBox1
and a button button1
with the following functions:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object Sender, EventArgs e) {
textBox1.Text = "Line before exception";
throw_Exception();
textBox1.Text = "Line after exception";
}
private void throw_Exception() => throw new Exception();
}
With this you see "Line before exception", then the exception dialogue (yay), but even if you hit continue, you do not reach "Line after exception". Obviously this is a silly example, but I am still unclear on what the continue button is actually doing. If the exception was thrown at the bottom of a large hierarchy does execution of everything up to the UI level stop? Does garbage collection run on any objects created before the exception? What if the exception is thrown on one thread of a multithreaded program?
Disclaimer: Yes, I know that there shouldn't be unhandled exceptions, and I certainly should not be throwing a general System.Exception
. I am just asking how the continue operation works under the hood and how to determine what state a system is in if the continue button is pressed.