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