Frames | No Frames |
1: /* gnu/regexp/REException.java 2: Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 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. 10: 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. 15: 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. 20: 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. 25: 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. */ 37: 38: package gnu.regexp; 39: 40: import java.text.MessageFormat; 41: 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> 52: * 53: * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> 54: */ 55: 56: public class REException extends Exception { 57: private int type; 58: private int pos; 59: 60: // Error conditions from GNU regcomp(3) manual 61: 62: /** 63: * Error flag. 64: * Invalid use of repetition operators such as using 65: * `*' as the first character. 66: */ 67: public static final int REG_BADRPT = 1; 68: 69: /** 70: * Error flag. 71: * Invalid use of back reference operator. 72: */ 73: public static final int REG_BADBR = 2; 74: 75: /** 76: * Error flag. 77: * Un-matched brace interval operators. 78: */ 79: public static final int REG_EBRACE = 3; 80: 81: /** 82: * Error flag. 83: * Un-matched bracket list operators. 84: */ 85: public static final int REG_EBRACK = 4; 86: 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. 92: */ 93: public static final int REG_ERANGE = 5; 94: 95: /** 96: * Error flag. 97: * Unknown character class name. <B>Not implemented</B>. 98: */ 99: public static final int REG_ECTYPE = 6; 100: 101: /** 102: * Error flag. 103: * Un-matched parenthesis group operators. 104: */ 105: public static final int REG_EPAREN = 7; 106: 107: /** 108: * Error flag. 109: * Invalid back reference to a subexpression. 110: */ 111: public static final int REG_ESUBREG = 8; 112: 113: /** 114: * Error flag. 115: * Non specific error. <B>Not implemented</B>. 116: */ 117: public static final int REG_EEND = 9; 118: 119: /** 120: * Error flag. 121: * Invalid escape sequence. <B>Not implemented</B>. 122: */ 123: public static final int REG_ESCAPE = 10; 124: 125: /** 126: * Error flag. 127: * Invalid use of pattern operators such as group or list. 128: */ 129: public static final int REG_BADPAT = 11; 130: 131: /** 132: * Error flag. 133: * Compiled regular expression requires a pattern 134: * buffer larger than 64Kb. <B>Not implemented</B>. 135: */ 136: public static final int REG_ESIZE = 12; 137: 138: /** 139: * Error flag. 140: * The regex routines ran out of memory. <B>Not implemented</B>. 141: */ 142: public static final int REG_ESPACE = 13; 143: 144: REException(String msg, int type, int position) { 145: super(msg); 146: this.type = type; 147: this.pos = position; 148: } 149: 150: /** 151: * Returns the type of the exception, one of the constants listed above. 152: */ 153: 154: public int getType() { 155: return type; 156: } 157: 158: /** 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. 163: */ 164: public int getPosition() { 165: return pos; 166: } 167: 168: /** 169: * Reports the descriptive message associated with this exception 170: * as well as its index position in the string or character array 171: * being compiled. 172: */ 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)); 178: sb.append('\n'); 179: sb.append(super.getMessage()); 180: return sb.toString(); 181: } 182: }