1 /* gnu/regexp/REException.java
2 Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 import java
.text
.MessageFormat
;
43 * This is the regular expression exception class. An exception of this type
44 * defines the three attributes:
46 * <LI> A descriptive message of the error.
47 * <LI> An integral type code equivalent to one of the statically
48 * defined symbols listed below.
49 * <LI> The approximate position in the input string where the error
53 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
56 public class REException
extends Exception
{
60 // Error conditions from GNU regcomp(3) manual
64 * Invalid use of repetition operators such as using
65 * `*' as the first character.
67 public static final int REG_BADRPT
= 1;
71 * Invalid use of back reference operator.
73 public static final int REG_BADBR
= 2;
77 * Un-matched brace interval operators.
79 public static final int REG_EBRACE
= 3;
83 * Un-matched bracket list operators.
85 public static final int REG_EBRACK
= 4;
89 * Invalid use of the range operator, eg. the ending
90 * point of the range occurs prior to the starting
93 public static final int REG_ERANGE
= 5;
97 * Unknown character class name. <B>Not implemented</B>.
99 public static final int REG_ECTYPE
= 6;
103 * Un-matched parenthesis group operators.
105 public static final int REG_EPAREN
= 7;
109 * Invalid back reference to a subexpression.
111 public static final int REG_ESUBREG
= 8;
115 * Non specific error. <B>Not implemented</B>.
117 public static final int REG_EEND
= 9;
121 * Invalid escape sequence. <B>Not implemented</B>.
123 public static final int REG_ESCAPE
= 10;
127 * Invalid use of pattern operators such as group or list.
129 public static final int REG_BADPAT
= 11;
133 * Compiled regular expression requires a pattern
134 * buffer larger than 64Kb. <B>Not implemented</B>.
136 public static final int REG_ESIZE
= 12;
140 * The regex routines ran out of memory. <B>Not implemented</B>.
142 public static final int REG_ESPACE
= 13;
144 REException(String msg
, int type
, int position
) {
151 * Returns the type of the exception, one of the constants listed above.
154 public int getType() {
159 * Returns the position, relative to the string or character array being
160 * compiled, where the error occurred. This position is generally the point
161 * where the error was detected, not necessarily the starting index of
162 * a bad subexpression.
164 public int getPosition() {
169 * Reports the descriptive message associated with this exception
170 * as well as its index position in the string or character array
173 public String
getMessage() {
174 Object
[] args
= {new Integer(pos
)};
175 StringBuffer sb
= new StringBuffer();
176 String prefix
= RE
.getLocalizedMessage("error.prefix");
177 sb
.append(MessageFormat
.format(prefix
, args
));
179 sb
.append(super.getMessage());
180 return sb
.toString();