It works fine for me, regardless of if I create a form instance and try that:
private void Button1_Click(object sender, EventArgs e)
{
FrmMain form = new FrmMain();
try
{
form.Close();
form.Show();
}
catch (ObjectDisposedException)
{
form.Show();
}
}
Or I use the existing form:
private void Button1_Click(object sender, EventArgs e)
{
try
{
Close();
Show();
}
catch (ObjectDisposedException)
{
Show();
}
}
Either way, the debugger shows the catch working fine.
I think you are confused, because you will get an identical exception inside the catch handler when you try to Show the form for a second time. Try this:
private void Button1_Click(object sender, EventArgs e)
{
FrmMain form = new FrmMain();
try
{
form.Close();
form.Show();
}
catch (ObjectDisposedException ex)
{
MessageBox.Show(ex.Message);
}
}
It should show you the error.