java.util.regex.PatternSyntaxException#getDescription ( )源码实例Demo

下面列出了java.util.regex.PatternSyntaxException#getDescription ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void performApply(IProgressMonitor monitor) throws CoreException {
  // normally should be handled by LanguageSettingsProviderTab
  final String text = pattern.getText();
  try {
    Pattern.compile(text);
  } catch (PatternSyntaxException ex) {
    // BUG in CDT: core exceptions thrown here are not visible to users. CDT-WTF
    // IStatus status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID,
    // IStatus.OK,
    // "invalid suffix pattern in CMAKE_EXPORT_COMPILE_COMMANDS Parser", ex);
    // throw new CoreException(status);

    throw new PatternSyntaxException(
        "Invalid suffix pattern in CMAKE_EXPORT_COMPILE_COMMANDS Parser:\n" + ex.getDescription(), ex.getPattern(),
        ex.getIndex());
  }
}
 
源代码2 项目: NekoSMS   文件: FilterEditorActivity.java
private String validatePatternString(SmsFilterPatternData patternData, int fieldNameId) {
    if (patternData.getMode() != SmsFilterMode.REGEX) {
        return null;
    }
    String pattern = patternData.getPattern();
    try {
        // We don't need the actual compiled pattern, this
        // is just to make sure the syntax is valid
        Pattern.compile(pattern);
    } catch (PatternSyntaxException e) {
        String description = e.getDescription();
        if (description == null) {
            description = getString(R.string.invalid_pattern_reason_unknown);
        }
        return getString(R.string.format_invalid_pattern_message, getString(fieldNameId), description);
    }
    return null;
}
 
private void throwExceptionOnInvalidFilterUrl(FilterConfiguration<R> filterConfig) {
	try {
		Pattern.compile(filterConfig.getUrl());
		if(filterConfig.getUrl().equals("/*")) {
			throw new PatternSyntaxException(filterConfig.getUrl(), "/*", 0);
		}
	} catch( PatternSyntaxException exception) {
		throw new FilterURLInvalidException(filterConfig.getUrl(), exception.getDescription());
	}
}