title: When does java.lang.EnumConstantNotPresentException gets thrown?
body: <p>As per java API EnumConstantNotPresentException gets thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name.</p>
  
  <p>Thus I decided to come up with a scenario where java.lang.EnumConstantNotPresentException will be thrown, so I wrote following three classes.</p>
  
  <p>MyEnum class:</p>
  
  <pre><code>package my.enumtest;
  
  enum MyEnum {
      A, B, C;
  }
  </code></pre>
  
  <p>MyEnumTest1 class:</p>
  
  <pre><code>package my.enumtest;
  
      import my.enumtest.MyEnum;
  
      class MyEnumTest1 {
  
          public static void main(String [] args) {
              System.out.println(MyEnum.A);        
          }        
      }
  </code></pre>
  
  <p>MyEnumTest2 class:</p>
  
  <pre><code>package my.enumtest;
  
  import my.enumtest.MyEnum;
  
  class MyEnumTest2 {
  
      public static void main(String [] args) {
          System.out.println(MyEnum.valueOf("A"));        
      }
  }
  </code></pre>
  
  <p>I compiled all three and then I changed the MyEnum class to drop constant 'A' and recompiled it:</p>
  
  <pre><code>package my.enumtest;
  
  enum MyEnum {
      B, C;
  }
  </code></pre>
  
  <p>On execution of MyEnumTest1 with new MyEnum class, I got following exception:</p>
  
  <blockquote>
    <p>Exception in thread "main"
    java.lang.NoSuchFieldError: A
            at my.enumtest.MyEnumTest1.main(MyEnumTest1.java:8)</p>
  </blockquote>
  
  <p>On execution of MyEnumTest2 with new MyEnum class, I got following exception:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IllegalArgumentException: No enum
    constant my.enumtest.MyEnum.A
            at java.lang.Enum.valueOf(Unknown Source)
            at my.enumtest.MyEnum.valueOf(MyEnum.java:3)
            at my.enumtest.MyEnumTest2.main(MyEnumTest2.java:8)</p>
  </blockquote>
  
  <p>As you can see in none of the cases I got EnumConstantNotPresentException, so can someone provide me usage of EnumConstantNotPresentException class?</p>
  
  <p><strong>P.S.</strong> I know that this exception can be thrown by the <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/AnnotatedElement.html" rel="nofollow">API</a> used to read annotations reflectively but I am looking for more obvious (simpler) scenario.</p>