Class RegexUtil.CheckedPatternSyntaxException
java.lang.Object
java.lang.Throwable
java.lang.Exception
org.checkerframework.checker.regex.util.RegexUtil.CheckedPatternSyntaxException
- All Implemented Interfaces:
- Serializable
- Enclosing class:
- RegexUtil
A checked version of 
PatternSyntaxException.
 This exception is useful when an illegal regex is detected but the contextual information to report a helpful error message is not available at the current depth in the call stack. By using a checked PatternSyntaxException the error must be handled up the call stack where a better error message can be reported.
Typical usage is:
 void myMethod(...) throws CheckedPatternSyntaxException {
   ...
   if (! isRegex(myString)) {
     throw new CheckedPatternSyntaxException(...);
   }
   ... Pattern.compile(myString) ...
 
 Simply calling Pattern.compile would have a similar effect, in that 
 PatternSyntaxException would be thrown at run time if myString is not a regular
 expression. There are two problems with such an approach. First, a client of myMethod
 might forget to handle the exception, since PatternSyntaxException is not checked.
 Also, the Regex Checker would issue a warning about the call to Pattern.compile that
 might throw an exception. The above usage pattern avoids both problems.- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionCheckedPatternSyntaxException(String desc, String regex, @org.checkerframework.checker.index.qual.GTENegativeOne int index) Constructs a new CheckedPatternSyntaxException.Constructs a new CheckedPatternSyntaxException equivalent to the givenPatternSyntaxException.
- 
Method SummaryModifier and TypeMethodDescriptionRetrieves the description of the error.intgetIndex()Retrieves the error index.Returns a multi-line string containing the description of the syntax error and its index, the erroneous regular-expression pattern, and a visual indication of the error index within the pattern.Retrieves the erroneous regular-expression pattern.Methods inherited from class java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
- 
Constructor Details- 
CheckedPatternSyntaxExceptionConstructs a new CheckedPatternSyntaxException equivalent to the givenPatternSyntaxException.Consider calling this constructor with the result of RegexUtil.regexError(java.lang.String).- Parameters:
- pse- the PatternSyntaxException to be wrapped
 
- 
CheckedPatternSyntaxExceptionpublic CheckedPatternSyntaxException(String desc, String regex, @org.checkerframework.checker.index.qual.GTENegativeOne int index) Constructs a new CheckedPatternSyntaxException.- Parameters:
- desc- a description of the error
- regex- the erroneous pattern
- index- the approximate index in the pattern of the error, or- -1if the index is not known
 
 
- 
- 
Method Details- 
getDescriptionRetrieves the description of the error.- Returns:
- the description of the error
 
- 
getIndexpublic int getIndex()Retrieves the error index.- Returns:
- the approximate index in the pattern of the error, or -1if the index is not known
 
- 
getMessageReturns a multi-line string containing the description of the syntax error and its index, the erroneous regular-expression pattern, and a visual indication of the error index within the pattern.- Overrides:
- getMessagein class- Throwable
- Returns:
- the full detail message
 
- 
getPatternRetrieves the erroneous regular-expression pattern.- Returns:
- the erroneous pattern
 
 
-