title: Why is debugging with some exceptions enabled much slower?
body: <p>Consider following code:</p>
  
  <pre><code>public class JMain {
      private final static int forLength = 6;
  
      private static void returnFromFor(int breakAt) {
          try {
              for (int j = 0; j &lt; forLength; j++) {
                  if (j == breakAt) {
                      throw new Throwable("break");
                  }
              }
          } catch (Throwable ignored) {
          }
      }
  
      public static void main(String args[]) {
          long start = System.currentTimeMillis();
          int iterations = 100000;
          for (int i = 0; i &lt; iterations; i++) {
              returnFromFor(i % forLength);
          }
  
          long end = System.currentTimeMillis();
          System.out.println(((Long) (end - start)).toString() + " ms");
      }
  }
  </code></pre>
  
  <p>When I run this code in IntelliJ IDEA debugger with exception breakpoint enabled for <code>java.lang.IllegalArgumentException</code>, it runs very slow, about 1800 ms on my computer. When I run it with no exceptions breakpoints, or with breakpoint enabled for <code>java.lang.UnsupportedOperationException</code>, it is about 10x faster.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li><p>why is debugging with <code>IllegalArgumentException</code> much slower than with <code>UnsupportedOperationException</code>?</p></li>
  <li><p>it the slowdown caused by the JVM debugger, or by IntelliJ?</p></li>
  </ul>
  
  <p>The system I am running this on is:</p>
  
  <ul>
  <li>Windows x64</li>
  <li>IntelliJ IDEA Ultimate 2018.2</li>
  <li>JRE: 1.8.0_152-release-1248-b8 amd64</li>
  </ul>
  
  <p><em>Note: the code above is demonstrating the issue I have with a complex Scala. If anyone is interested in the more natural Scala code demonstration, here it comes:</em></p>
  
  <pre><code>object Main extends App {
  
    val forLength = 6
    def returnFromFor(breakAt: Int): Unit = {
      for (j &lt;- 0 until forLength) {
        if (j == breakAt) return
      }
    }
  
    val start = System.currentTimeMillis()
    val iterations = 100000
    for (i &lt;- 0 until iterations) {
      returnFromFor(i%forLength)
    }
    val end = System.currentTimeMillis()
    println(s"Duration ${end-start} ms")
  
  }
  </code></pre>