I have a method which uses proxies to retrieve information from a server. Sometimes due to a bad proxy I get
public String getTest(int i, int current, int total)
String text = "";
if (i == 1)
throw new IOException();
else if (i == 2)
throw new SSLException("SSLEx");
else if (i == 3)
throw new SocketException();
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)
System.out.println(c.getTest(3, 0, 5));
i = 1
In order to return the string returned by your recursive function call, you must place
return before the recursive function call like so...
return getTest(1, ++current, total);
Right now you are simply running the recursive function and discarding its return value. Your logic then returns your
text string from the initial call (which in the case of an
SSLException looks like an empty string).
You could also accomplish the same effect by assigning
text from the recursive function...
text = getTest(1, ++current, total);
Both statements, considering the rest of your logic, are equivalent.