Merge with trank @ 137446
[official-gcc.git] / libjava / classpath / gnu / java / util / regex / REException.java
blob7a277ca3ae3d6631003fa40965a590c6f51cbbf5
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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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. */
38 package gnu.java.util.regex;
40 import java.text.MessageFormat;
42 /**
43 * This is the regular expression exception class. An exception of this type
44 * defines the three attributes:
45 * <OL>
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
50 * occurred.
51 * </OL>
53 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
56 public class REException extends Exception {
57 private int type;
58 private int pos;
60 // Error conditions from GNU regcomp(3) manual
62 /**
63 * Error flag.
64 * Invalid use of repetition operators such as using
65 * `*' as the first character.
67 public static final int REG_BADRPT = 1;
69 /**
70 * Error flag.
71 * Invalid use of back reference operator.
73 public static final int REG_BADBR = 2;
75 /**
76 * Error flag.
77 * Un-matched brace interval operators.
79 public static final int REG_EBRACE = 3;
81 /**
82 * Error flag.
83 * Un-matched bracket list operators.
85 public static final int REG_EBRACK = 4;
87 /**
88 * Error flag.
89 * Invalid use of the range operator, eg. the ending
90 * point of the range occurs prior to the starting
91 * point.
93 public static final int REG_ERANGE = 5;
95 /**
96 * Error flag.
97 * Unknown character class name. <B>Not implemented</B>.
99 public static final int REG_ECTYPE = 6;
102 * Error flag.
103 * Un-matched parenthesis group operators.
105 public static final int REG_EPAREN = 7;
108 * Error flag.
109 * Invalid back reference to a subexpression.
111 public static final int REG_ESUBREG = 8;
114 * Error flag.
115 * Non specific error. <B>Not implemented</B>.
117 public static final int REG_EEND = 9;
120 * Error flag.
121 * Invalid escape sequence. <B>Not implemented</B>.
123 public static final int REG_ESCAPE = 10;
126 * Error flag.
127 * Invalid use of pattern operators such as group or list.
129 public static final int REG_BADPAT = 11;
132 * Error flag.
133 * Compiled regular expression requires a pattern
134 * buffer larger than 64Kb. <B>Not implemented</B>.
136 public static final int REG_ESIZE = 12;
139 * Error flag.
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) {
145 super(msg);
146 this.type = type;
147 this.pos = position;
150 REException(String msg, Throwable cause, int type, int position) {
151 super(msg, cause);
152 this.type = type;
153 this.pos = position;
157 * Returns the type of the exception, one of the constants listed above.
160 public int getType() {
161 return type;
165 * Returns the position, relative to the string or character array being
166 * compiled, where the error occurred. This position is generally the point
167 * where the error was detected, not necessarily the starting index of
168 * a bad subexpression.
170 public int getPosition() {
171 return pos;
175 * Reports the descriptive message associated with this exception
176 * as well as its index position in the string or character array
177 * being compiled.
179 public String getMessage() {
180 Object[] args = {new Integer(pos)};
181 StringBuffer sb = new StringBuffer();
182 String prefix = RE.getLocalizedMessage("error.prefix");
183 sb.append(MessageFormat.format(prefix, args));
184 sb.append('\n');
185 sb.append(super.getMessage());
186 return sb.toString();