001: /*
002: * gnu/regexp/REException.java
003: * Copyright (C) 1998 Wes Biggs
004: *
005: * This library is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU Library General Public License as published
007: * by the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU Library General Public License for more details.
014: *
015: * You should have received a copy of the GNU Library General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018: */
019:
020: package gnu.regexp;
021:
022: /**
023: * This is the regular expression exception class. An exception of this type
024: * defines the three attributes:
025: * <OL>
026: * <LI> A descriptive message of the error.
027: * <LI> An integral type code equivalent to one of the statically
028: * defined symbols listed below.
029: * <LI> The approximate position in the input string where the error
030: * occurred.
031: * </OL>
032: *
033: * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
034: */
035:
036: public class REException extends Exception {
037: private int m_type;
038: private int m_pos;
039:
040: // Error conditions from GNU regcomp(3) manual
041:
042: /**
043: * Error flag.
044: * Invalid use of repetition operators such as using
045: * `*' as the first character.
046: */
047: public static final int REG_BADRPT = 1;
048:
049: /**
050: * Error flag.
051: * Invalid use of back reference operator.
052: */
053: public static final int REG_BADBR = 2;
054:
055: /**
056: * Error flag.
057: * Un-matched brace interval operators.
058: */
059: public static final int REG_EBRACE = 3;
060:
061: /**
062: * Error flag.
063: * Un-matched bracket list operators.
064: */
065: public static final int REG_EBRACK = 4;
066:
067: /**
068: * Error flag.
069: * Invalid use of the range operator, eg. the ending
070: * point of the range occurs prior to the starting
071: * point.
072: */
073: public static final int REG_ERANGE = 5;
074:
075: /**
076: * Error flag.
077: * Unknown character class name. <B>Not implemented</B>.
078: */
079: public static final int REG_ECTYPE = 6;
080:
081: /**
082: * Error flag.
083: * Un-matched parenthesis group operators.
084: */
085: public static final int REG_EPAREN = 7;
086:
087: /**
088: * Error flag.
089: * Invalid back reference to a subexpression.
090: */
091: public static final int REG_ESUBREG = 8;
092:
093: /**
094: * Error flag.
095: * Non specific error. <B>Not implemented</B>.
096: */
097: public static final int REG_EEND = 9;
098:
099: /**
100: * Error flag.
101: * Invalid escape sequence. <B>Not implemented</B>.
102: */
103: public static final int REG_ESCAPE = 10;
104:
105: /**
106: * Error flag.
107: * Invalid use of pattern operators such as group or list.
108: */
109: public static final int REG_BADPAT = 11;
110:
111: /**
112: * Error flag.
113: * Compiled regular expression requires a pattern
114: * buffer larger than 64Kb. <B>Not implemented</B>.
115: */
116: public static final int REG_ESIZE = 12;
117:
118: /**
119: * Error flag.
120: * The regex routines ran out of memory. <B>Not implemented</B>.
121: */
122: public static final int REG_ESPACE = 13;
123:
124: REException(String msg, int type, int position) {
125: super (msg);
126: m_type = type;
127: m_pos = position;
128: }
129:
130: /**
131: * Returns the type of the exception, one of the constants listed above.
132: */
133:
134: public int getType() {
135: return m_type;
136: }
137:
138: /**
139: * Returns the position, relative to the string or character array being
140: * compiled, where the error occurred. This position is generally the point
141: * where the error was detected, not necessarily the starting index of
142: * a bad subexpression.
143: */
144: public int getPosition() {
145: return m_pos;
146: }
147:
148: /**
149: * Reports the descriptive message associated with this exception
150: * as well as its index position in the string or character array
151: * being compiled.
152: */
153: public String getMessage() {
154: StringBuffer sb = new StringBuffer();
155: sb.append("At position " + m_pos
156: + " in regular expression pattern: ");
157: sb.append('\n');
158: sb.append(super.getMessage());
159: return sb.toString();
160: }
161: }
|