在代码的评论中查看问题。我应该如何处理两个类之间的异常?
我有两个类。
这里的主类(第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()的最佳方法来报告错误返回到调用方法?
调用者需要知道是否有错误以及错误消息是什么。我将如何去发送调用方法这两条信息?
应将类DoSomething称为计算和方法计算名为DevideNumbers? –
请澄清你的答案,分开问题和代码。另外,你在void方法中返回一个int。 – Andre
我更新了一切。 – Testifier