public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
Throws: IllegalArgumentException - if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type NullPointerException - if enumType or name is null Since: 1.5
If I have to see EnumConstantNotPresentException
public class EnumConstantNotPresentException extends RuntimeException
Thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name.
But when I click on the Use link on this page, see what I got
Uses of Class java.lang.EnumConstantNotPresentException No usage of java.lang.EnumConstantNotPresentException
Sorry, I should have read all the preceding posts. OK. I think that probably the exception will be thrown if one class refers to an enum value from another class, but then the other class is changed and recompiled so that it no longer contains the referenced enum value. In order for this to work, you don't try to recompile the second class, the one that references the formerly-valid value. You just run its code. If you tried to recompile, you would get a compile error. But if you run the previously-compiled file, the only option is to get a runtime exception or error.
I grepped through the source code of Sun JDK 6 and found only one place where this exception is used: in interface java.lang.reflect.AnnotatedElement. The API documentation for that interface says:
Represents an annotated element of the program currently running in this VM. This interface allows annotations to be read reflectively. All annotations returned by methods in this interface are immutable and serializable. It is permissible for the caller to modify the arrays returned by accessors for array-valued enum members; it will have no affect on the arrays returned to other callers.
If an annotation returned by a method in this interface contains (directly or indirectly) a Class-valued member referring to a class that is not accessible in this VM, attempting to read the class by calling the relevant Class-returning method on the returned annotation will result in a TypeNotPresentException.
Similarly, attempting to read an enum-valued member will result in a EnumConstantNotPresentException if the enum constant in the annotation is no longer present in the enum type.
Finally, Attempting to read a member whose definition has evolved incompatibly will result in a AnnotationTypeMismatchException or an IncompleteAnnotationException.
Note: You do not need to know this for the SCJP exam.