FileDocCategorySizeDatePackage
PatternSyntaxException.javaAPI DocAndroid 1.5 API4220Wed May 06 22:41:04 BST 2009java.util.regex

PatternSyntaxException

public 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.
see
Pattern#compile(String)
see
Pattern#compile(java.lang.String,int)
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private String
pattern
Holds the syntactically incorrect regular expression, or null if the regular expression is not known.
private String
description
Holds the description of the syntax error, or null if the description is not known.
private int
index
Holds 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.

param
description the description of the syntax error, or {@code null} if the description is not known.
param
pattern the syntactically incorrect regular expression, or {@code null} if the regular expression is not known.
param
index the character index around which the error occurred, or -1 if the index is not known.
since
Android 1.0


                                                                                                                                               
           
        this.pattern = pattern;
        this.description = description;
        this.index = index;
    
Methods Summary
public java.lang.StringgetDescription()
Returns the description of the syntax error, or {@code null} if the description is not known.

return
the description.
since
Android 1.0

        return description;
    
public intgetIndex()
Returns the character index around which the error occurred, or -1 if the index is not known.

return
the index.
since
Android 1.0

        return index;
    
public java.lang.StringgetMessage()
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.

return
the error message.
since
Android 1.0

        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.StringgetPattern()
Returns the syntactically incorrect regular expression.

return
the regular expression.
since
Android 1.0

        return pattern;