I have a FormA
from which I open FormB
like so:
FormB B = new FormB();
FormB.ShowDialog();
In FormB
, I have some code in a try catch block and when it throws the exception, FormB
is closed.
private void func()
{
try
{
// some code
DialogResult = DialogResult.Ok;
throw new Exception("Test exception")
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Take look at that two lines of code. When DialogResult assignment is above exception throw, form closes after exception.
Vice versa, the form is not closing. So can someone explain that behavior?