Tricky try-catch java code
<pre><code>public class Strange1 {
  public static void main(String[] args) {
    try {
      Missing m = new Missing();
    } catch (java.lang.NoClassDefFoundError ex) {
      System.out.println("Got it!");
    }
  }
}

public class Strange2 {
  public static void main(String[] args) {
    Missing m;
    try {
      m = new Missing();
    } catch (java.lang.NoClassDefFoundError ex) {
      System.out.println("Got it!");
    }
  }
}

class Missing {
  Missing() { }
}
</code></pre>

<p>If you run Strange1 and Strange2 after deleting <code>Missing.class</code>, Strange1 will throw <code>NoClassDefFoundError;</code> but Strange2 will print Got it！</p>

<p>Can anyone explain that? Thanks.</p>

<p>updated:</p>

<p>java bytecode for <code>Strange1</code> :</p>

<pre><code>     0  new info.liuxuan.test.Missing [16]
     3  dup
     4  invokespecial info.liuxuan.test.Missing() [18]
     7  astore_1 [m]
     8  goto 20
    11  astore_1 [ex]
    12  getstatic java.lang.System.out : java.io.PrintStream [19]
    15  ldc &lt;String "Got it!"&gt; [25]
    17  invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]
    20  return
      Exception Table:
        [pc: 0, pc: 8] -&gt; 11 when : java.lang.NoClassDefFoundError
      Line numbers:
        [pc: 0, line: 14]
        [pc: 11, line: 15]
        [pc: 12, line: 16]
        [pc: 20, line: 18]
      Local variable table:
        [pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]
        [pc: 8, pc: 11] local: m index: 1 type: info.liuxuan.test.Missing
        [pc: 12, pc: 20] local: ex index: 1 type: java.lang.NoClassDefFoundError
</code></pre>

<p>java bytecode for <code>Strange2</code> :</p>

<pre><code>     0  new info.liuxuan.test.Missing [16]
     3  dup
     4  invokespecial info.liuxuan.test.Missing() [18]
     7  astore_1 [m]
     8  goto 20
    11  astore_2 [ex]
    12  getstatic java.lang.System.out : java.io.PrintStream [19]
    15  ldc &lt;String "Got it!"&gt; [25]
    17  invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]
    20  return
      Exception Table:
        [pc: 0, pc: 8] -&gt; 11 when : java.lang.NoClassDefFoundError
      Line numbers:
        [pc: 0, line: 15]
        [pc: 11, line: 16]
        [pc: 12, line: 17]
        [pc: 20, line: 19]
      Local variable table:
        [pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]
        [pc: 8, pc: 11] local: m index: 1 type: info.liuxuan.test.Missing
        [pc: 12, pc: 20] local: ex index: 2 type: java.lang.NoClassDefFoundError
</code></pre>

<p>There is only one place is different:</p>

<pre><code>11  astore_1 [ex]
</code></pre>

<p>and </p>

<pre><code>11  astore_2 [ex]
</code></pre>

<p>updated again:</p>

<p>Everyone can try it in eclipse.</p>
