1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package com.gargoylesoftware.base.util;
39
40
41 /***
42 * A more detailed version of IllegalArgumentException that contains
43 * information about what argument was not legal.
44 *
45 * @version $Revision: 1.5 $
46 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
47 */
48 public class DetailedIllegalArgumentException extends IllegalArgumentException {
49 private static final long serialVersionUID = -6090279070118149533L;
50 private final String argumentName_;
51 private final Object argumentValue_;
52
53
54 /***
55 * Create an instance
56 *
57 * @param argumentName The name of the argument that was illegal
58 * @param argumentValue The illegal value
59 * @param message The message to use in the exception
60 */
61 public DetailedIllegalArgumentException(
62 final String argumentName, final Object argumentValue, final String message ) {
63
64 super("argumentName=["+argumentName+"] argumentValue=["+argumentValue+"]"
65 + (message==null?"":" message=["+message+"]"));
66
67 argumentName_ = argumentName;
68 argumentValue_ = argumentValue;
69 }
70
71
72 /***
73 * Create an instance
74 *
75 * @param argumentName The name of the argument that was illegal
76 * @param argumentValue The illegal value
77 */
78 public DetailedIllegalArgumentException(
79 final String argumentName, final Object argumentValue ) {
80
81 this( argumentName, argumentValue, null );
82 }
83
84
85 /***
86 * Create an instance
87 *
88 * @param argumentName The name of the argument that was illegal
89 * @param argumentValue The illegal value
90 * @param message A message
91 */
92 public DetailedIllegalArgumentException(
93 final String argumentName, final int argumentValue, final String message ) {
94
95 this(argumentName, new Integer(argumentValue), message);
96 }
97
98
99 /***
100 * Create an instance
101 *
102 * @param argumentName The name of the argument that was illegal
103 * @param argumentValue The illegal value
104 */
105 public DetailedIllegalArgumentException(
106 final String argumentName, final int argumentValue ) {
107
108 this(argumentName, new Integer(argumentValue));
109 }
110
111
112 /***
113 * Return the name of the argument that was illegal
114 * @return the name of the argument
115 */
116 public String getArgumentName() {
117 return argumentName_;
118 }
119
120
121 /***
122 * Return the value of the argument
123 * @return The value of the argument
124 */
125 public Object getArgumentValue() {
126 return argumentValue_;
127 }
128 }
129