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. package java.lang;
  8. /**
  9. * Thrown when an application tries to access an enum constant by name
  10. * and the enum type contains no constant with the specified name.
  11. *
  12. * @author Josh Bloch
  13. * @since 1.5
  14. */
  15. public class EnumConstantNotPresentException extends RuntimeException {
  16. /**
  17. * The type of the missing enum constant.
  18. */
  19. private Class<? extends Enum> enumType;
  20. /**
  21. * The name of the missing enum constant.
  22. */
  23. private String constantName;
  24. /**
  25. * Constructs an <tt>EnumConstantNotPresentException</tt> for the
  26. * specified constant.
  27. *
  28. * @param enumType the type of the missing enum constant
  29. * @param constantName the name of the missing enum constant
  30. */
  31. public EnumConstantNotPresentException(Class<? extends Enum> enumType,
  32. String constantName) {
  33. super(enumType.getName() + "." + constantName);
  34. this.enumType = enumType;
  35. this.constantName = constantName;
  36. }
  37. /**
  38. * Returns the type of the missing enum constant.
  39. *
  40. * @return the type of the missing enum constant
  41. */
  42. public Class<? extends Enum> enumType() { return enumType; }
  43. /**
  44. * Returns the name of the missing enum constant.
  45. *
  46. * @return the name of the missing enum constant
  47. */
  48. public String constantName() { return constantName; }
  49. }