title: In Java, what is the best way of continuing to call a function until no exception is thrown?
body: <p>In my Java code, I have a function called <code>getAngle()</code> which sometimes throws a <code>NoAngleException</code>. Is the following code the best way of writing a function that keeps calling <code>getAngle()</code> until no exception is thrown?</p>
  
  <pre><code>public int getAngleBlocking()
  {
      while(true)
      {
          int angle;
          try
          {
              angle = getAngle();
              return angle;
          }
          catch(NoAngleException e)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>Or would it be a better idea to rewrite <code>getAngle()</code> to return <code>NaN</code> upon error?</p>