PatternSyntaxExceptionpublic class PatternSyntaxException extends IllegalArgumentException Encapsulates a syntax error that occurred during the compilation of a
{@link Pattern}. Might include a detailed description, the original regular
expression, and the index at which the error occurred. |
Fields Summary |
---|
private static final long | serialVersionUID | private String | patternHolds the syntactically incorrect regular expression, or null if the
regular expression is not known. | private String | descriptionHolds the description of the syntax error, or null if the description is
not known. | private int | indexHolds the index around which the error occured, or -1, in case it is
unknown. |
Constructors Summary |
---|
public PatternSyntaxException(String description, String pattern, int index)Creates a new PatternSyntaxException for a given message, pattern, and
error index.
this.pattern = pattern;
this.description = description;
this.index = index;
|
Methods Summary |
---|
public java.lang.String | getDescription()Returns the description of the syntax error, or {@code null} if the
description is not known.
return description;
| public int | getIndex()Returns the character index around which the error occurred, or -1 if the
index is not known.
return index;
| public java.lang.String | getMessage()Returns a detailed error message for the exception. The message is
potentially multi-line, and it might include a detailed description, the
original regular expression, and the index at which the error occured.
StringBuilder builder = new StringBuilder("Syntax error");
if (description != null) {
builder.append(' ");
builder.append(description);
}
if (index >= 0) {
builder.append(" near index " + index + ":");
}
if (pattern != null) {
builder.append('\n");
builder.append(pattern);
if (index >= 0) {
char[] spaces = new char[index];
Arrays.fill(spaces, ' ");
builder.append('\n");
builder.append(spaces);
builder.append('^");
}
}
return builder.toString();
| public java.lang.String | getPattern()Returns the syntactically incorrect regular expression.
return pattern;
|
|