请参阅代码注释中的问题。
我有两节课。
这是主要课程(第 1 课):
//this class contains controls on the form.
Class MyApp
{
private void btnProcessImages_Click(object sender, EventArgs e)
{
/* if an error occurs in the method below, I want to:
1. Show the error message, and
2. Based on fail or success do different actions.
*/
Calculate.DevideNumbers(2, 0);
}
/*
if the above is successful, I want to do 1 thing,
if not, i want to do something else (with controls on THIS form).
*/
}
这是第二类:
Class Calculate
{
public double void DivideNumbers(int num1, int num2)
{
double result = 0.00;
try
{
result = num1/num2;
return result;
}
catch (Exception)
{
throw;
}
}
}
我的问题是: DivideNumbers() 向调用方法报告错误的最佳方式是什么?
调用者需要知道是否有错误以及错误消息是什么。我将如何发送这两条信息的调用方法?