1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.lang;
18
19 /**
20 * <p>Thrown to indicate that an argument was <code>null</code> and should
21 * not have been.
22 * This exception supplements the standard <code>IllegalArgumentException</code>
23 * by providing a more semantically rich description of the problem.</p>
24 *
25 * <p><code>NullArgumentException</code> represents the case where a method takes
26 * in a parameter that must not be <code>null</code>.
27 * Some coding standards would use <code>NullPointerException</code> for this case,
28 * others will use <code>IllegalArgumentException</code>.
29 * Thus this exception would be used in place of
30 * <code>IllegalArgumentException</code>, yet it still extends it.</p>
31 *
32 * <pre>
33 * public void foo(String str) {
34 * if (str == null) {
35 * throw new NullArgumentException("str");
36 * }
37 * // do something with the string
38 * }
39 * </pre>
40 *
41 * @author Matthew Hawthorne
42 * @author Stephen Colebourne
43 * @since 2.0
44 * @version $Id: NullArgumentException.java 437554 2006-08-28 06:21:41Z bayard $
45 */
46 public class NullArgumentException extends IllegalArgumentException {
47
48 /**
49 * Required for serialization support.
50 *
51 * @see java.io.Serializable
52 */
53 private static final long serialVersionUID = 1174360235354917591L;
54
55 /**
56 * <p>Instantiates with the given argument name.</p>
57 *
58 * @param argName the name of the argument that was <code>null</code>.
59 */
60 public NullArgumentException(String argName) {
61 super((argName == null ? "Argument" : argName) + " must not be null.");
62 }
63
64 }