我在我的一個類中有以下代碼。這個類的目的是爲了從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