001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.lang;
018    
019    /**
020     * <p>Thrown to indicate that an argument was <code>null</code> and should
021     * not have been.
022     * This exception supplements the standard <code>IllegalArgumentException</code>
023     * by providing a more semantically rich description of the problem.</p>
024     * 
025     * <p><code>NullArgumentException</code> represents the case where a method takes
026     * in a parameter that must not be <code>null</code>.
027     * Some coding standards would use <code>NullPointerException</code> for this case,
028     * others will use <code>IllegalArgumentException</code>.
029     * Thus this exception would be used in place of
030     * <code>IllegalArgumentException</code>, yet it still extends it.</p>
031     * 
032     * <pre>
033     * public void foo(String str) {
034     *   if (str == null) {
035     *     throw new NullArgumentException("str");
036     *   }
037     *   // do something with the string
038     * }
039     * </pre>
040     * 
041     * @author Apache Software Foundation
042     * @author Matthew Hawthorne
043     * @since 2.0
044     * @version $Id: NullArgumentException.java 905636 2010-02-02 14:03:32Z niallp $
045     */
046    public class NullArgumentException extends IllegalArgumentException {
047    
048        /**
049         * Required for serialization support.
050         * 
051         * @see java.io.Serializable
052         */
053        private static final long serialVersionUID = 1174360235354917591L;
054    
055        /**
056         * <p>Instantiates with the given argument name.</p>
057         *
058         * @param argName  the name of the argument that was <code>null</code>.
059         */
060        public NullArgumentException(String argName) {
061            super((argName == null ? "Argument" : argName) + " must not be null.");
062        }
063    
064    }