1. /*
  2. * @(#)IllegalFormatConversionException.java 1.3 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.util;
  8. /**
  9. * Unchecked exception thrown when the argument corresponding to the format
  10. * specifier is of an incompatible type.
  11. *
  12. * <p> Unless otherwise specified, passing a <tt>null</tt> argument to any
  13. * method or constructor in this class will cause a {@link
  14. * NullPointerException} to be thrown.
  15. *
  16. * @version 1.3, 05/05/04
  17. * @since 1.5
  18. */
  19. public class IllegalFormatConversionException extends IllegalFormatException {
  20. private static final long serialVersionUID = 17000126L;
  21. private char c;
  22. private Class arg;
  23. /**
  24. * Constructs an instance of this class with the mismatched conversion and
  25. * the corresponding argument class.
  26. *
  27. * @param c
  28. * Inapplicable conversion
  29. *
  30. * @param arg
  31. * Class of the mismatched argument
  32. */
  33. public IllegalFormatConversionException(char c, Class<?> arg) {
  34. if (arg == null)
  35. throw new NullPointerException();
  36. this.c = c;
  37. this.arg = arg;
  38. }
  39. /**
  40. * Returns the inapplicable conversion.
  41. *
  42. * @return The inapplicable conversion
  43. */
  44. public char getConversion() {
  45. return c;
  46. }
  47. /**
  48. * Returns the class of the mismatched argument.
  49. *
  50. * @return The class of the mismatched argument
  51. */
  52. public Class<?> getArgumentClass() {
  53. return arg;
  54. }
  55. // javadoc inherited from Throwable.java
  56. public String getMessage() {
  57. return String.format("%c != %s", c, arg.getName());
  58. }
  59. }