我在我的一个类中有以下代码。这个类的目的是为了从Web服务器获得平衡。以防万一出现了平衡问题。我会处理一个例外。但是,这一切都很容易。但是我仍然想知道我的声明中会回复什么。C#从异常句柄返回一些东西
大部分我看着例子只是写来使用控制台:
Console.WriteLine(ex.Message);
这是所有非常好。但是在实际应用中,大多数开发人员做什么?
//Download only when the webclient is not busy.
if (!wc.IsBusy)
{
// Sleep for 1/2 second to give the server time to update the balance.
System.Threading.Thread.Sleep(500);
try
{
// Download the current balance.
wc.DownloadStringAsync(new Uri(strURL));
}
catch (WebException ex)
{
Console.Write("GetBalance(): " + ex.Message);
}
}
else
{
Console.Write("Busy please try again");
}
我的函数此刻返回void。我只是想知道如果Web客户端忙碌,我还会返回什么?
非常感谢任何建议,
如果每个方法都实现了延迟 - 重试循环,则将它们嵌套三个深度,并且您已经尝试了重试的次数。这样做很危险。 – 2009-04-29 02:25:55