I\'m trying to do this:
I\'m creating another form, which in it\'s FormClosed method throws an exception, that should be caught by the main form.
Main Form:<
You'll be able to do this as follows:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2(this);
form2.Show();
}
public void HandleForm2Exception(Exception ex)
{
MessageBox.Show("EXCEPTION HAPPENED!");
}
}
and on Form2.cs
public partial class Form2 : Form
{
private Form1 form1;
public Form2(Form1 form1) : this()
{
this.form1 = form1;
}
public Form2()
{
InitializeComponent();
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
throw new Exception();
}
catch (Exception ex)
{
if(this.form1 != null)
this.form1.HandleForm2Exception(ex);
}
}
}