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         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  
18  package org.apache.commons.cli;
19  
20  /**
21   * Base for Exceptions thrown during parsing of a command-line.
22   */
23  public class ParseException extends Exception {
24  
25      /**
26       * This exception {@code serialVersionUID}.
27       */
28      private static final long serialVersionUID = 9112808380089253192L;
29  
30      /**
31       * Converts any exception except {@code UnsupportedOperationException} to a {@code ParseException}.
32       * if {@code e} is an instance of {@code ParseException} it is returned, otherwise a {@code ParseException} is
33       * created that wraps it.
34       * <p>
35       * Note: {@code UnsupportedOperationException} are not wrapped.  This is to solve a legacy expected exception problem and will be
36       * removed in the future.</p>
37       * @param e the exception to convert.
38       * @return the ParseException.
39       * @throws UnsupportedOperationException due to legacy expectations.  Will be removed in the future.
40       * @since 1.7.0
41       */
42      public static ParseException wrap(final Throwable e) throws UnsupportedOperationException {
43          if (e instanceof UnsupportedOperationException) {
44              throw (UnsupportedOperationException) e;
45          }
46  
47          if (e instanceof ParseException) {
48              return (ParseException) e;
49          }
50          return new ParseException(e);
51      }
52  
53      /**
54       * Constructs a new {@code ParseException} with the specified detail message.
55       *
56       * @param message the detail message
57       */
58      public ParseException(final String message) {
59          super(message);
60      }
61  
62      /**
63       * Constructs a new {@code ParseException} wrapping the specified exception.
64       *
65       * @param e the Exception to wrap.
66       */
67      public ParseException(final Throwable e) {
68          super(e);
69      }
70  }