Source code: com/memoire/re/REException.java
1
2
3 package com.memoire.re;
4 import com.memoire.re.*;
5
6 /*
7 * gnu/regexp/REException.java
8 * Copyright (C) 1998 Wes Biggs
9 *
10 * This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25
26
27 /**
28 * This is the regular expression exception class. An exception of this type
29 * defines the three attributes:
30 * <OL>
31 * <LI> A descriptive message of the error.
32 * <LI> An integral type code equivalent to one of the statically
33 * defined symbols listed below.
34 * <LI> The approximate position in the input string where the error
35 * occurred.
36 * </OL>
37 *
38 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
39 */
40
41 public class REException extends Exception {
42 private int m_type;
43 private int m_pos;
44
45 // Error conditions from GNU regcomp(3) manual
46
47 /**
48 * Error flag.
49 * Invalid use of repetition operators such as using
50 * `*' as the first character.
51 */
52 public static final int REG_BADRPT = 1;
53
54 /**
55 * Error flag.
56 * Invalid use of back reference operator.
57 */
58 public static final int REG_BADBR = 2;
59
60 /**
61 * Error flag.
62 * Un-matched brace interval operators.
63 */
64 public static final int REG_EBRACE = 3;
65
66 /**
67 * Error flag.
68 * Un-matched bracket list operators.
69 */
70 public static final int REG_EBRACK = 4;
71
72 /**
73 * Error flag.
74 * Invalid use of the range operator, eg. the ending
75 * point of the range occurs prior to the starting
76 * point.
77 */
78 public static final int REG_ERANGE = 5;
79
80 /**
81 * Error flag.
82 * Unknown character class name. <B>Not implemented</B>.
83 */
84 public static final int REG_ECTYPE = 6;
85
86 /**
87 * Error flag.
88 * Un-matched parenthesis group operators.
89 */
90 public static final int REG_EPAREN = 7;
91
92 /**
93 * Error flag.
94 * Invalid back reference to a subexpression.
95 */
96 public static final int REG_ESUBREG = 8;
97
98 /**
99 * Error flag.
100 * Non specific error. <B>Not implemented</B>.
101 */
102 public static final int REG_EEND = 9;
103
104 /**
105 * Error flag.
106 * Invalid escape sequence. <B>Not implemented</B>.
107 */
108 public static final int REG_ESCAPE = 10;
109
110 /**
111 * Error flag.
112 * Invalid use of pattern operators such as group or list.
113 */
114 public static final int REG_BADPAT = 11;
115
116 /**
117 * Error flag.
118 * Compiled regular expression requires a pattern
119 * buffer larger than 64Kb. <B>Not implemented</B>.
120 */
121 public static final int REG_ESIZE = 12;
122
123 /**
124 * Error flag.
125 * The regex routines ran out of memory. <B>Not implemented</B>.
126 */
127 public static final int REG_ESPACE = 13;
128
129 REException(String msg, int type, int position) {
130 super(msg);
131 m_type = type;
132 m_pos = position;
133 }
134
135 /**
136 * Returns the type of the exception, one of the constants listed above.
137 */
138
139 public int getType() {
140 return m_type;
141 }
142
143 /**
144 * Returns the position, relative to the string or character array being
145 * compiled, where the error occurred. This position is generally the point
146 * where the error was detected, not necessarily the starting index of
147 * a bad subexpression.
148 */
149 public int getPosition() {
150 return m_pos;
151 }
152
153 /**
154 * Reports the descriptive message associated with this exception
155 * as well as its index position in the string or character array
156 * being compiled.
157 */
158 public String getMessage() {
159 StringBuffer sb = new StringBuffer();
160 sb.append("At position "+m_pos+" in regular expression pattern: ");
161 sb.append('\n');
162 sb.append(super.getMessage());
163 return sb.toString();
164 }
165 }