title: Limiting try block scope. Does it matter?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2633834/should-java-try-blocks-be-scoped-as-tightly-as-possible">Should java try blocks be scoped as tightly as possible?</a>  </p>
  </blockquote>
  
  
  
  <p>Is there any performance benefit (particularly in C++ or Java) in keeping the size of try block small [aside from it being more informative to the reader as to which statement can throw].</p>
  
  <p>Given the following method where i do not want to throw out of the method.</p>
  
  <pre><code>void function() throws Exception
  {
      statement1
      statement2
      statement3 // can throw
      statement4
      statement5
  }
  </code></pre>
  
  <p>Is it better to do this:</p>
  
  <p><strong>Option 1</strong></p>
  
  <pre><code>void function()
  {
      try {
          statement1
          statement2
          statement3 // can throw
          statement4
          statement5
      }
      catch (...) {
      }
  }
  </code></pre>
  
  <p>or</p>
  
  <p><strong>Option 2</strong></p>
  
  <pre><code>void function()
  {
      statement1
      statement2
  
      boolean success = false;
      try {
          statement3 // can throw
          success = true;
      }
      catch (...) {
      }
  
      if (success)
      {
          statement4
          statement5
      }
  }
  </code></pre>