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 *      https://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 */
017package org.apache.commons.lang3;
018
019/**
020 * Thrown to indicate that a block of code has not been implemented.
021 * This exception supplements {@link UnsupportedOperationException}
022 * by providing a more semantically rich description of the problem.
023 *
024 * <p>
025 * {@link NotImplementedException} represents the case where the
026 * author has yet to implement the logic at this point in the program.
027 * This can act as an exception based TODO tag.
028 * </p>
029 *
030 * <pre>
031 * public void foo() {
032 *   try {
033 *     // do something that throws an Exception
034 *   } catch (Exception ex) {
035 *     // don't know what to do here yet
036 *     throw new NotImplementedException("TODO", ex);
037 *   }
038 * }
039 * </pre>
040 *
041 * This class was originally added in Lang 2.0, but removed in 3.0.
042 *
043 * @since 3.2
044 */
045public class NotImplementedException extends UnsupportedOperationException {
046
047    private static final long serialVersionUID = 20131021L;
048
049    /** A resource for more information regarding the lack of implementation. */
050    private final String code;
051
052    /**
053     * Constructs a NotImplementedException.
054     *
055     * @since 3.10
056     */
057    public NotImplementedException() {
058        this.code = null;
059    }
060
061    /**
062     * Constructs a NotImplementedException.
063     *
064     * @param message description of the exception
065     * @since 3.2
066     */
067    public NotImplementedException(final String message) {
068        this(message, (String) null);
069    }
070
071    /**
072     * Constructs a NotImplementedException.
073     *
074     * @param message description of the exception
075     * @param code code indicating a resource for more information regarding the lack of implementation
076     * @since 3.2
077     */
078    public NotImplementedException(final String message, final String code) {
079        super(message);
080        this.code = code;
081    }
082
083    /**
084     * Constructs a NotImplementedException.
085     *
086     * @param message description of the exception
087     * @param cause cause of the exception
088     * @since 3.2
089     */
090    public NotImplementedException(final String message, final Throwable cause) {
091        this(message, cause, null);
092    }
093
094    /**
095     * Constructs a NotImplementedException.
096     *
097     * @param message description of the exception
098     * @param cause cause of the exception
099     * @param code code indicating a resource for more information regarding the lack of implementation
100     * @since 3.2
101     */
102    public NotImplementedException(final String message, final Throwable cause, final String code) {
103        super(message, cause);
104        this.code = code;
105    }
106
107    /**
108     * Constructs a NotImplementedException.
109     *
110     * @param cause cause of the exception
111     * @since 3.2
112     */
113    public NotImplementedException(final Throwable cause) {
114        this(cause, null);
115    }
116
117    /**
118     * Constructs a NotImplementedException.
119     *
120     * @param cause cause of the exception
121     * @param code code indicating a resource for more information regarding the lack of implementation
122     * @since 3.2
123     */
124    public NotImplementedException(final Throwable cause, final String code) {
125        super(cause);
126        this.code = code;
127    }
128
129    /**
130     * Gets the code identifying why this operation is not implemented. This unformatted text can point to further information, such as an issue tracker ID or a
131     * URL.
132     *
133     * @return A code indicating a resource for more information regarding the lack of implementation
134     */
135    public String getCode() {
136        return this.code;
137    }
138}