title: Functionality for automatic retry after exception
body: <p>I have made this abstract class to automatically retry network calls if some exception is thrown. </p>
  
  <ul>
  <li>I take care to not retry after <code>InterruptedException</code> &amp;
  <code>UnknownHostException</code>. </li>
  <li>I retry 5 times.  After each failure
  I perform an exponential back off, starting from 300ms going upto
  1500ms.</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>public abstract class AutoRetry {
  
    private Object dataToReturn = null;
    public Object getDataToReturn() {
      return this.dataToReturn;
    }
  
    public AutoRetry() {
  
      short retry = -1;
      while (retry++ &lt; StaticData.NETWORK_RETRY) {
  
        try {
          Thread.sleep(retry * StaticData.NETWORK_CALL_WAIT);
          this.dataToReturn = doWork();
          break;
        } catch (InterruptedException | UnknownHostException e) {
          e.printStackTrace();
          this.dataToReturn = null;
          return;
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  
    protected abstract Object doWork() throws IOException;
  }
  </code></pre>
  
  <p>I use it as follows : </p>
  
  <pre class="lang-js prettyprint-override"><code>final Object dataAfterWork = new AutoRetry() {     
    @Override
    protected Object doWork() throws IOException {
      return; //a network call which returns something
    }
  }.getDataToReturn();
  </code></pre>
  
  <p>So is this implementation good/correct ?</p>
  
  <hr>
  
  <h2>EDIT</h2>
  
  <p>moved to <a href="https://codereview.stackexchange.com/questions/87686">https://codereview.stackexchange.com/questions/87686</a></p>