View Javadoc
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    *      https://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.lang3;
18  
19  /**
20   * Thrown to indicate that a block of code has not been implemented.
21   * This exception supplements {@link UnsupportedOperationException}
22   * by providing a more semantically rich description of the problem.
23   *
24   * <p>
25   * {@link NotImplementedException} represents the case where the
26   * author has yet to implement the logic at this point in the program.
27   * This can act as an exception based TODO tag.
28   * </p>
29   *
30   * <pre>
31   * public void foo() {
32   *   try {
33   *     // do something that throws an Exception
34   *   } catch (Exception ex) {
35   *     // don't know what to do here yet
36   *     throw new NotImplementedException("TODO", ex);
37   *   }
38   * }
39   * </pre>
40   *
41   * This class was originally added in Lang 2.0, but removed in 3.0.
42   *
43   * @since 3.2
44   */
45  public class NotImplementedException extends UnsupportedOperationException {
46  
47      private static final long serialVersionUID = 20131021L;
48  
49      /** A resource for more information regarding the lack of implementation. */
50      private final String code;
51  
52      /**
53       * Constructs a NotImplementedException.
54       *
55       * @since 3.10
56       */
57      public NotImplementedException() {
58          this.code = null;
59      }
60  
61      /**
62       * Constructs a NotImplementedException.
63       *
64       * @param message description of the exception
65       * @since 3.2
66       */
67      public NotImplementedException(final String message) {
68          this(message, (String) null);
69      }
70  
71      /**
72       * Constructs a NotImplementedException.
73       *
74       * @param message description of the exception
75       * @param code code indicating a resource for more information regarding the lack of implementation
76       * @since 3.2
77       */
78      public NotImplementedException(final String message, final String code) {
79          super(message);
80          this.code = code;
81      }
82  
83      /**
84       * Constructs a NotImplementedException.
85       *
86       * @param message description of the exception
87       * @param cause cause of the exception
88       * @since 3.2
89       */
90      public NotImplementedException(final String message, final Throwable cause) {
91          this(message, cause, null);
92      }
93  
94      /**
95       * Constructs a NotImplementedException.
96       *
97       * @param message description of the exception
98       * @param cause cause of the exception
99       * @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 }