Possible Duplicate:
How to catch exceptions
I have not really had to use try and catch exceptions. I am trying to use a try/catch to trap for potential errors. Now I am not to sure where to put the try and catch this is the code I have right now..
divide d;
private void button1_Click(object sender, EventArgs e)
{
d = new divide(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
int total = d.CalculateDivision();
MessageBox.Show(total.ToString());
}
now would I put it under here with
try
{
}
catch
{
MessageBox.Show("error");
}
or would I add the try/ catch somewhere in the code.
see http://msdn.microsoft.com/en-us/library/ms173160.aspx
The
trygoes around the code where the exception is thrown and the value is handled. in your example:as you can only show the total if there is no exception.