title: Why does processing try-catch without any exception thrown not slow down the program at all?
body: <p>Today I realized something that appeared weird to me: I noticed that when I just do</p>
  
  <pre><code>try {
      doSomething();
  } catch (Exception e) {
  }
  </code></pre>
  
  <p>it isn't slower at all than if I just do</p>
  
  <pre><code>doSomething();
  </code></pre>
  
  <p>So I ran a test and wrote down some quick code to prove what I saw, the code basically just loops over a function called doSomething() lots of times, one time without and one time with try-catch surrounding it. So here's the code to it if you want to test it yourself:    </p>
  
  <pre><code>public class Main {
  
  private static final long LOOPS = 1000000L;
  
  public static final void main(String[] args)
  {
      System.out.println("Loop without try catch: "+loopWithoutTryCatch(LOOPS));
      System.out.println("Loop with try catch: "+loopWithTryCatch(LOOPS));
  }
  
  public static long loopWithoutTryCatch(long loops)
  {
      long startTime = System.currentTimeMillis();
  
      for (long i = 0L; i &lt; loops; i++)
      {
          doSomething();
      }
  
      return System.currentTimeMillis()-startTime;
  }
  
  public static long loopWithTryCatch(long loops)
  {
      long startTime = System.currentTimeMillis();
  
      for (long i = 0L; i &lt; loops; i++)
      {
          try {
              doSomething();
          } catch (Exception e) {
          }
      }
  
      return System.currentTimeMillis()-startTime;
  }
  
  public static void doSomething()
  {
      for (int i = 0; i &lt; 250; i++)
      {
          if (i % 3 == 0)
          {
              i++;
          }
      }
  }
  }
  </code></pre>
  
  <p>And I received the following output: </p>
  
  <pre><code>Loop without try catch: 375
  Loop with try catch: 373
  </code></pre>
  
  <p>I was surprised so I tested it again and again, but I always got similar results, both ways it runs pretty much in the same time. </p>
  
  <p>And now my question is: Why?</p>
  
  <p>I dont really understand it, as far as I know try-catch writes the resources before usage in some kind of table to later - if any exception is thrown - be able to clean it up and reference to the values it had before the exception occured. </p>
  
  <p>This should take at least some time, shouldn't it? 
  I thought it is maybe because I the random example I choose doesnt represent it properly, and in that specific case in which I tested it it doesnt slow down anything, but that seemed very unlikely to me. </p>
  
  <p>Then I thought maybe it just takes such a tiny amount of time that it isnt noticable with that "few" amount of executions, so I ran the test program again with a total number of 10 million loopings, but what I found just prooved what I had already found: It takes pretty much the same time for both executions.</p>
  
  <p>So is there any logical explanation for that this is the case or just a example-specific behaviour of try-catch? </p>
  
  <p>Thanks for any clarification in advance.</p>