0
我有一個使用代理從服務器檢索信息的方法。有時由於錯誤的代理,我得到SocketException
,SSLException
,SSLHandshakeException
或ConnectException
重試一些例外遞歸
我想方法對異常重試以上,但對IOException異常或沒有例外,我想一個字符串返回
這裏是方法我構建了測試不同的場景
public String getTest(int i, int current, int total)
{
String text = "";
try
{
if (i == 1)
throw new IOException();
else if (i == 2)
throw new SSLException("SSLEx");
else if (i == 3)
throw new SocketException();
else
text = "EVERYTHING GOOD";
}
catch (SSLException | SocketException re)
{
if (current < total)
{
System.out.println("Recalling " + current);
getTest(1, ++current, total);
}
}
catch (IOException ioe)
{
text = "HTTP ERROR";
}
catch (Exception e)
{
e.printStackTrace();
}
return text;
}
我通過
System.out.println(c.getTest(3, 0, 5));
打電話給我的測試方法
最初計劃將搭上SocketException
隨後通過1重試,所以我可以模仿一個工作代理,但與服務器響應IOException
爲i = 1
,但此方法不會返回文本「HTTP錯誤」
什麼我需要改變爲了這個按預期工作?
我試着從函數http://pastebin.com/82GHJQBc分配文本,看起來現在正在工作 – Arya
很高興聽到它! – DeathByTensors