KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > NullArgumentException


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang;
17
18 /**
19  * <p>Thrown to indicate that an argument was <code>null</code> and should
20  * not have been.
21  * This exception supplements the standard <code>IllegalArgumentException</code>
22  * by providing a more semantically rich description of the problem.</p>
23  *
24  * <p><code>NullArgumentException</code> represents the case where a method takes
25  * in a parameter that must not be <code>null</code>.
26  * Some coding standards would use <code>NullPointerException</code> for this case,
27  * others will use <code>IllegalArgumentException</code>.
28  * Thus this exception would be used in place of
29  * <code>IllegalArgumentException</code>, yet it still extends it.</p>
30  *
31  * <pre>
32  * public void foo(String str) {
33  * if (str == null) {
34  * throw new NullArgumentException("str");
35  * }
36  * // do something with the string
37  * }
38  * </pre>
39  *
40  * @author Matthew Hawthorne
41  * @author Stephen Colebourne
42  * @since 2.0
43  * @version $Id: NullArgumentException.java 161243 2005-04-14 04:30:28Z ggregory $
44  */

45 public class NullArgumentException extends IllegalArgumentException JavaDoc {
46
47    /**
48     * <p>Instantiates with the given argument name.</p>
49     *
50     * @param argName the name of the argument that was <code>null</code>.
51     */

52     public NullArgumentException(String JavaDoc argName) {
53         super((argName == null ? "Argument" : argName) + " must not be null.");
54     }
55
56 }
57
Popular Tags