KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > EnumConstantNotPresentException


1 /*
2  * @(#)EnumConstantNotPresentException.java 1.1 04/02/03
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang;
9
10 /**
11  * Thrown when an application tries to access an enum constant by name
12  * and the enum type contains no constant with the specified name.
13  *
14  * @author Josh Bloch
15  * @since 1.5
16  */

17 public class EnumConstantNotPresentException extends RuntimeException JavaDoc {
18     /**
19      * The type of the missing enum constant.
20      */

21     private Class JavaDoc<? extends Enum JavaDoc> enumType;
22
23     /**
24      * The name of the missing enum constant.
25      */

26     private String JavaDoc constantName;
27
28     /**
29      * Constructs an <tt>EnumConstantNotPresentException</tt> for the
30      * specified constant.
31      *
32      * @param enumType the type of the missing enum constant
33      * @param constantName the name of the missing enum constant
34      */

35     public EnumConstantNotPresentException(Class JavaDoc<? extends Enum JavaDoc> enumType,
36                                            String JavaDoc constantName) {
37         super(enumType.getName() + "." + constantName);
38     this.enumType = enumType;
39     this.constantName = constantName;
40     }
41
42     /**
43      * Returns the type of the missing enum constant.
44      *
45      * @return the type of the missing enum constant
46      */

47     public Class JavaDoc<? extends Enum JavaDoc> enumType() { return enumType; }
48
49     /**
50      * Returns the name of the missing enum constant.
51      *
52      * @return the name of the missing enum constant
53      */

54     public String JavaDoc constantName() { return constantName; }
55 }
56
Popular Tags