2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
30 * Checked exception thrown to indicate that a string could not be parsed as a
33 * @author Mark Reinhold
38 public class URISyntaxException
41 private static final long serialVersionUID = 2137979680897488891L;
47 * Constructs an instance from the given input string, reason, and error
50 * @param input The input string
51 * @param reason A string explaining why the input could not be parsed
52 * @param index The index at which the parse error occurred,
53 * or <tt>-1</tt> if the index is not known
55 * @throws NullPointerException
56 * If either the input or reason strings are <tt>null</tt>
58 * @throws IllegalArgumentException
59 * If the error index is less than <tt>-1</tt>
61 public URISyntaxException(String input, String reason, int index) {
63 if ((input == null) || (reason == null))
64 throw new NullPointerException();
66 throw new IllegalArgumentException();
72 * Constructs an instance from the given input string and reason. The
73 * resulting object will have an error index of <tt>-1</tt>.
75 * @param input The input string
76 * @param reason A string explaining why the input could not be parsed
78 * @throws NullPointerException
79 * If either the input or reason strings are <tt>null</tt>
81 public URISyntaxException(String input, String reason) {
82 this(input, reason, -1);
86 * Returns the input string.
88 * @return The input string
90 public String getInput() {
95 * Returns a string explaining why the input string could not be parsed.
97 * @return The reason string
99 public String getReason() {
100 return super.getMessage();
104 * Returns an index into the input string of the position at which the
105 * parse error occurred, or <tt>-1</tt> if this position is not known.
107 * @return The error index
109 public int getIndex() {
114 * Returns a string describing the parse error. The resulting string
115 * consists of the reason string followed by a colon character
116 * (<tt>':'</tt>), a space, and the input string. If the error index is
117 * defined then the string <tt>" at index "</tt> followed by the index, in
118 * decimal, is inserted after the reason string and before the colon
121 * @return A string describing the parse error
123 public String getMessage() {
124 StringBuffer sb = new StringBuffer();
125 sb.append(getReason());
127 sb.append(" at index ");
132 return sb.toString();