2 * gnu/regexp/REException.java
3 * Copyright (C) 1998-2001 Wes Biggs
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 import java.text.MessageFormat;
25 * This is the regular expression exception class. An exception of this type
26 * defines the three attributes:
28 * <LI> A descriptive message of the error.
29 * <LI> An integral type code equivalent to one of the statically
30 * defined symbols listed below.
31 * <LI> The approximate position in the input string where the error
35 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
38 public class REException extends Exception {
42 // Error conditions from GNU regcomp(3) manual
46 * Invalid use of repetition operators such as using
47 * `*' as the first character.
49 public static final int REG_BADRPT = 1;
53 * Invalid use of back reference operator.
55 public static final int REG_BADBR = 2;
59 * Un-matched brace interval operators.
61 public static final int REG_EBRACE = 3;
65 * Un-matched bracket list operators.
67 public static final int REG_EBRACK = 4;
71 * Invalid use of the range operator, eg. the ending
72 * point of the range occurs prior to the starting
75 public static final int REG_ERANGE = 5;
79 * Unknown character class name. <B>Not implemented</B>.
81 public static final int REG_ECTYPE = 6;
85 * Un-matched parenthesis group operators.
87 public static final int REG_EPAREN = 7;
91 * Invalid back reference to a subexpression.
93 public static final int REG_ESUBREG = 8;
97 * Non specific error. <B>Not implemented</B>.
99 public static final int REG_EEND = 9;
103 * Invalid escape sequence. <B>Not implemented</B>.
105 public static final int REG_ESCAPE = 10;
109 * Invalid use of pattern operators such as group or list.
111 public static final int REG_BADPAT = 11;
115 * Compiled regular expression requires a pattern
116 * buffer larger than 64Kb. <B>Not implemented</B>.
118 public static final int REG_ESIZE = 12;
122 * The regex routines ran out of memory. <B>Not implemented</B>.
124 public static final int REG_ESPACE = 13;
126 REException(String msg, int type, int position) {
133 * Returns the type of the exception, one of the constants listed above.
136 public int getType() {
141 * Returns the position, relative to the string or character array being
142 * compiled, where the error occurred. This position is generally the point
143 * where the error was detected, not necessarily the starting index of
144 * a bad subexpression.
146 public int getPosition() {
151 * Reports the descriptive message associated with this exception
152 * as well as its index position in the string or character array
155 public String getMessage() {
156 Object[] args = {new Integer(pos)};
157 StringBuffer sb = new StringBuffer();
158 String prefix = RE.getLocalizedMessage("error.prefix");
159 sb.append(MessageFormat.format(prefix, args));
161 sb.append(super.getMessage());
162 return sb.toString();