Please see the code below:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
mymethod();
}
catch (Exception ex)//First catch
{
MessageBox.Show(ex.ToString());
}
}
private void mymethod()
{
int a = 10;
int b = 0;
try
{
int c = a / b;
}
catch (Exception ex)//Second catch
{
MessageBox.Show(ex.ToString());
//int c = a / b;
throw new Exception(ex.ToString());
}
}
}
I want to force the first catch
to execute after the second catch
executes! How can I force the above to run and show the second catch
error? I want to see the same ex.ToString()
for both catch
blocks.
Thanks in advance.