KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > util > IllegalFormatConversionException


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
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 1.3, 05/05/04
19  * @since 1.5
20  */

21 public class IllegalFormatConversionException extends IllegalFormatException JavaDoc {
22
23     private static final long serialVersionUID = 17000126L;
24
25     private char c;
26     private Class JavaDoc 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 JavaDoc<?> arg) {
39     if (arg == null)
40         throw new NullPointerException JavaDoc();
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 JavaDoc<?> getArgumentClass() {
60     return arg;
61     }
62
63     // javadoc inherited from Throwable.java
64
public String JavaDoc getMessage() {
65     return String.format("%c != %s", c, arg.getName());
66     }
67 }
68
Popular Tags