libjava/ChangeLog:
[official-gcc.git] / libjava / classpath / gnu / java / util / regex / REException.java
blob5681ceeea6abba261f1df53330cc8ca5da25b324
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 gnu.java.lang.CPStringBuilder;
42 import java.text.MessageFormat;
44 /**
45 * This is the regular expression exception class. An exception of this type
46 * defines the three attributes:
47 * <OL>
48 * <LI> A descriptive message of the error.
49 * <LI> An integral type code equivalent to one of the statically
50 * defined symbols listed below.
51 * <LI> The approximate position in the input string where the error
52 * occurred.
53 * </OL>
55 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
58 public class REException extends Exception
60 private int type;
61 private int pos;
63 // Error conditions from GNU regcomp(3) manual
65 /**
66 * Error flag.
67 * Invalid use of repetition operators such as using
68 * `*' as the first character.
70 public static final int REG_BADRPT = 1;
72 /**
73 * Error flag.
74 * Invalid use of back reference operator.
76 public static final int REG_BADBR = 2;
78 /**
79 * Error flag.
80 * Un-matched brace interval operators.
82 public static final int REG_EBRACE = 3;
84 /**
85 * Error flag.
86 * Un-matched bracket list operators.
88 public static final int REG_EBRACK = 4;
90 /**
91 * Error flag.
92 * Invalid use of the range operator, eg. the ending
93 * point of the range occurs prior to the starting
94 * point.
96 public static final int REG_ERANGE = 5;
98 /**
99 * Error flag.
100 * Unknown character class name. <B>Not implemented</B>.
102 public static final int REG_ECTYPE = 6;
105 * Error flag.
106 * Un-matched parenthesis group operators.
108 public static final int REG_EPAREN = 7;
111 * Error flag.
112 * Invalid back reference to a subexpression.
114 public static final int REG_ESUBREG = 8;
117 * Error flag.
118 * Non specific error. <B>Not implemented</B>.
120 public static final int REG_EEND = 9;
123 * Error flag.
124 * Invalid escape sequence. <B>Not implemented</B>.
126 public static final int REG_ESCAPE = 10;
129 * Error flag.
130 * Invalid use of pattern operators such as group or list.
132 public static final int REG_BADPAT = 11;
135 * Error flag.
136 * Compiled regular expression requires a pattern
137 * buffer larger than 64Kb. <B>Not implemented</B>.
139 public static final int REG_ESIZE = 12;
142 * Error flag.
143 * The regex routines ran out of memory. <B>Not implemented</B>.
145 public static final int REG_ESPACE = 13;
147 REException (String msg, int type, int position)
149 super (msg);
150 this.type = type;
151 this.pos = position;
154 REException (String msg, Throwable cause, int type, int position)
156 super (msg, cause);
157 this.type = type;
158 this.pos = position;
162 * Returns the type of the exception, one of the constants listed above.
165 public int getType ()
167 return type;
171 * Returns the position, relative to the string or character array being
172 * compiled, where the error occurred. This position is generally the point
173 * where the error was detected, not necessarily the starting index of
174 * a bad subexpression.
176 public int getPosition ()
178 return pos;
182 * Reports the descriptive message associated with this exception
183 * as well as its index position in the string or character array
184 * being compiled.
186 public String getMessage ()
188 Object[]args =
190 new Integer (pos)};
191 CPStringBuilder sb = new CPStringBuilder ();
192 String prefix = RE.getLocalizedMessage ("error.prefix");
193 sb.append (MessageFormat.format (prefix, args));
194 sb.append ('\n');
195 sb.append (super.getMessage ());
196 return sb.toString ();