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.
(String specifier)
| 111 | * @throws ParseException if the specifier is not valid. |
| 112 | */ |
| 113 | @CanIgnoreReturnValue // TODO(b/219820829): consider removing |
| 114 | public static HostSpecifier from(String specifier) throws ParseException { |
| 115 | try { |
| 116 | return fromValid(specifier); |
| 117 | } catch (IllegalArgumentException e) { |
| 118 | // Since the IAE can originate at several different points inside |
| 119 | // fromValid(), we implement this method in terms of that one rather |
| 120 | // than the reverse. |
| 121 | |
| 122 | ParseException parseException = new ParseException("Invalid host specifier: " + specifier, 0); |
| 123 | parseException.initCause(e); |
| 124 | throw parseException; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Determines whether {@code specifier} represents a valid {@link HostSpecifier} as described in |