title: Should try...catch go inside or outside a loop?
body: <p>I have a loop that looks something like this:</p>
  
  <pre><code>for (int i = 0; i &lt; max; i++) {
      String myString = ...;
      float myNum = Float.parseFloat(myString);
      myFloats[i] = myNum;
  }
  </code></pre>
  
  <p>This is the main content of a method whose sole purpose is to return the array of floats. I want this method to return <code>null</code> if there is an error, so I put the loop inside a <code>try...catch</code> block, like this:</p>
  
  <pre><code>try {
      for (int i = 0; i &lt; max; i++) {
          String myString = ...;
          float myNum = Float.parseFloat(myString);
          myFloats[i] = myNum;
      }
  } catch (NumberFormatException ex) {
      return null;
  }
  </code></pre>
  
  <p>But then I also thought of putting the <code>try...catch</code> block inside the loop, like this:</p>
  
  <pre><code>for (int i = 0; i &lt; max; i++) {
      String myString = ...;
      try {
          float myNum = Float.parseFloat(myString);
      } catch (NumberFormatException ex) {
          return null;
      }
      myFloats[i] = myNum;
  }
  </code></pre>
  
  <p>Is there any reason, performance or otherwise, to prefer one over the other?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> The consensus seems to be that it is cleaner to put the loop inside the try/catch, possibly inside its own method. However, there is still debate on which is faster. Can someone test this and come back with a unified answer?</p>