/** * Attempts to return a {@code HostSpecifier} for the given string, throwing an exception if * parsing fails. Always use this method in preference to {@link #fromValid(String)} for a * specifier that is not already known to be valid. * * @throws ParseException if the specifier is not valid. */ public static HostSpecifier from(String specifier) throws ParseException { try { return fromValid(specifier); } catch (IllegalArgumentException e) { // Since the IAE can originate at several different points inside // fromValid(), we implement this method in terms of that one rather // than the reverse. ParseException parseException = new ParseException("Invalid host specifier: " + specifier, 0); parseException.initCause(e); throw parseException; } }
/** * Attempts to return a {@code HostSpecifier} for the given string, throwing an exception if * parsing fails. Always use this method in preference to {@link #fromValid(String)} for a * specifier that is not already known to be valid. * * @throws ParseException if the specifier is not valid. */ public static HostSpecifier from(String specifier) throws ParseException { try { return fromValid(specifier); } catch (IllegalArgumentException e) { // Since the IAE can originate at several different points inside // fromValid(), we implement this method in terms of that one rather // than the reverse. ParseException parseException = new ParseException("Invalid host specifier: " + specifier, 0); parseException.initCause(e); throw parseException; } }
/** * Attempts to return a {@code HostSpecifier} for the given string, throwing an exception if * parsing fails. Always use this method in preference to {@link #fromValid(String)} for a * specifier that is not already known to be valid. * * @throws ParseException if the specifier is not valid. */ public static HostSpecifier from(String specifier) throws ParseException { try { return fromValid(specifier); } catch (IllegalArgumentException e) { // Since the IAE can originate at several different points inside // fromValid(), we implement this method in terms of that one rather // than the reverse. ParseException parseException = new ParseException("Invalid host specifier: " + specifier, 0); parseException.initCause(e); throw parseException; } }
/** * Attempts to return a {@code HostSpecifier} for the given string, throwing an exception if * parsing fails. Always use this method in preference to {@link #fromValid(String)} for a * specifier that is not already known to be valid. * * @throws ParseException if the specifier is not valid. */ public static HostSpecifier from(String specifier) throws ParseException { try { return fromValid(specifier); } catch (IllegalArgumentException e) { // Since the IAE can originate at several different points inside // fromValid(), we implement this method in terms of that one rather // than the reverse. ParseException parseException = new ParseException("Invalid host specifier: " + specifier, 0); parseException.initCause(e); throw parseException; } }
@Override public Date parse(String source) throws ParseException { ParseException head = null, tail = null; for (SimpleDateFormat formatter : formatters) { try { return formatter.parse(source); } catch (ParseException ex1) { /* * Adding all exceptions together to get some info in * the logs. */ ex1 = new ParseException( String.format("%s with format \"%s\" and locale \"%s\"", ex1.getMessage(), formatter.toPattern(), locale), ex1.getErrorOffset() ); if (head == null) { head = tail = ex1; } else { tail.initCause(ex1); tail = ex1; } } } throw head != null ? head : new ParseException(String.format("Unparseable date: \"%s\"", source), 0); }
private int readIntValue(HttpHeaderReader reader, String directiveName) throws ParseException { reader.nextSeparator('='); int index = reader.getIndex(); try { return Integer.parseInt(reader.nextToken().toString()); } catch (NumberFormatException nfe) { ParseException pe = new ParseException( "Error parsing integer value for " + directiveName + " directive", index); pe.initCause(nfe); throw pe; } }
private int readIntValue(HttpHeaderReader reader, String directiveName) throws ParseException { reader.nextSeparator('='); int index = reader.getIndex(); try { return Integer.parseInt(reader.nextToken().toString()); } catch (NumberFormatException nfe) { ParseException pe = new ParseException( "Error parsing integer value for " + directiveName + " directive", index); pe.initCause(nfe); throw pe; } }
/** * Parse the given version number as a constant or dot based version. * <p>This method allows to use {@code "LUCENE_X_Y"} constant names, * or version numbers in the format {@code "x.y.z"}. * * @lucene.internal */ public static Version parseLeniently(String version) throws ParseException { String versionOrig = version; version = version.toUpperCase(Locale.ROOT); switch (version) { case "LATEST": case "LUCENE_CURRENT": return LATEST; default: version = version .replaceFirst("^LUCENE_(\\d+)_(\\d+)_(\\d+)$", "$1.$2.$3") .replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2.0") .replaceFirst("^LUCENE_(\\d)(\\d)$", "$1.$2.0"); try { return parse(version); } catch (ParseException pe) { ParseException pe2 = new ParseException("failed to parse lenient version string \"" + versionOrig + "\": " + pe.getMessage(), 0); pe2.initCause(pe); throw pe2; } } }
ex.initCause(fail); throw ex;
ex.initCause(fail); throw ex;
} catch (NumberFormatException nfe) { ParseException p = new ParseException("Failed to parse major version from \"" + token + "\" (got: " + version + ")", 0); p.initCause(nfe); throw p; } catch (NumberFormatException nfe) { ParseException p = new ParseException("Failed to parse minor version from \"" + token + "\" (got: " + version + ")", 0); p.initCause(nfe); throw p; } catch (NumberFormatException nfe) { ParseException p = new ParseException("Failed to parse bugfix version from \"" + token + "\" (got: " + version + ")", 0); p.initCause(nfe); throw p; } catch (NumberFormatException nfe) { ParseException p = new ParseException("Failed to parse prerelease version from \"" + token + "\" (got: " + version + ")", 0); p.initCause(nfe); throw p; } catch (IllegalArgumentException iae) { ParseException pe = new ParseException("failed to parse version string \"" + version + "\": " + iae.getMessage(), 0); pe.initCause(iae); throw pe;
ex.initCause(fail); throw ex;
@Override public void parse(Reader in) throws IOException, ParseException { LineNumberReader br = new LineNumberReader(in); try { addInternal(br); } catch (IllegalArgumentException e) { ParseException ex = new ParseException("Invalid synonym rule at line " + br.getLineNumber(), 0); ex.initCause(e); throw ex; } finally { br.close(); } }
/** * Returns a {@link ParseException} with the specified cause. A localized string <code> * "Error in <{@link #keyword}>"</code> will be prepend to the message. The error index will be * the starting index of this {@code Element}. * * @param cause The cause of the failure, or {@code null} if none. * @param message The message explaining the cause of the failure, or {@code null} for reusing * the same message than {@code cause}. * @return The exception to be thrown. */ public ParseException parseFailed(final Exception cause, String message) { if (message == null) { message = cause.getLocalizedMessage(); } ParseException exception = new ParseException(complete(message), offset); exception = trim("parseFailed", exception); exception.initCause(cause); return exception; }
/** * Parses the specified Well Know Text without restriction on the expected type. The default * implementation delegates the work to <code> * {@link #parseObject(String,Class) parseObject}(wkt, Object.class)</code>. * * @param wkt The text to parse. * @return The parsed object. * @throws ParseException if the text can't be parsed. */ @Override public Object parseObject(final String wkt) throws ParseException { try { return parseObject(wkt, Object.class); } catch (FactoryException cause) { final ParseException e = new ParseException(cause.getLocalizedMessage(), 0); e.initCause(cause); throw e; } }
/** * Returns {@code data[index]} as a number. * * @param index Index of the value to returns. * @return The value as a {@link Number}. * @throws ParseException if the value can not be converted to a {@link Number}. */ private Number getNumber(final int index) throws ParseException { Exception error = null; if (data[index] instanceof Comparable) { try { return ClassChanger.toNumber((Comparable) data[index]); } catch (ClassNotFoundException exception) { error = exception; } } ParseException exception = new ParseException( Errors.format(ErrorKeys.UNPARSABLE_NUMBER_$1, data[index]), limits[index]); if (error != null) { exception.initCause(error); } throw exception; }
} catch (IllegalArgumentException e) { ParseException ex = new ParseException("Invalid synonym rule at line " + br.getLineNumber(), 0); ex.initCause(e); throw ex; } finally {
} catch (Exception e) { ParseException pe = new ParseException(e.toString(), state.offset); pe.initCause(e); throw pe;
ex.initCause(fail); throw ex;
new ParseException(exception.getLocalizedMessage(), errorOffset - shift); adjusted.setStackTrace(exception.getStackTrace()); adjusted.initCause(exception.getCause()); throw adjusted;