我还没有真正有使用尝试和捕捉异常。我正尝试使用try/catch来捕获潜在的错误。现在我不知道在哪里把尝试,赶上这是我现在所拥有的代码..
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());
}
现在我把它放在这里
try
{
}
catch
{
MessageBox.Show("error");
}
或我想补充的尝试/捕捉代码中的某处。
在哪里的问题?什么是“新分水岭”? – gdoron 2012-03-22 09:57:02
你知道try/catch有点贵。因此,您可以使用TryParse API并对上述代码进行一些重构以避免出现异常。 – Zenwalker 2012-03-22 09:57:33
如果它的web应用程序可以在Global.asax中使用Application_Error事件..请参阅http://stackoverflow.com/questions/9806832/general-exception-handling-without-global-asax-file – Flowerking 2012-03-22 09:57:37