Skip to main content
 首页 » 编程设计

c#之尝试/捕获异常

2024年02月23日19lvdongjie

<分区>

Possible Duplicate:
How to catch exceptions

我还没有真的必须使用 try 和 catch 异常。我正在尝试使用 try/catch 来捕获潜在的错误。现在我不确定将 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"); 
} 

或者我会在代码中的某处添加 try/catch。